Scala Code Snippets: Functional Programming and OOP

Scala Code Snippets: Functional and Object-Oriented Programming

Functional Programming Examples

Counting Equal Pairs with Tail Recursion

The cuentaIgualesTail function calculates the number of pairs in a list where the first element of the pair, when passed through a function f, is equal to the second element. It uses tail recursion for efficiency.

  def cuentaIgualesTail(listaTuplas: List[(Int,Int)], f: (Int)=> Int) : Int = {
    cuentaIgualesTailAux(listaTuplas,f,0)
  };

  def cuentaIgualesTailAux(
Read More

Machine Learning Algorithms: Practical Implementations

Find-S Algorithm Implementation in Python

This section demonstrates the Find-S algorithm using the Pandas library in Python.

First Find-S Example


import pandas as pd

attributes = ['AirTemp', 'Temp', 'Humidity', 'Wind', 'Water', 'Forecast']
num_attributes = len(attributes)
filename = pd.read_csv('Weather.csv')
print(filename)
target = ['Yes', 'Yes', 'No', 'Yes']
print(target)
hypothesis = ['0'] * num_attributes
for i in range(len(target)):
    if target[i] == 'Yes':
        for j in range(num_attributes)
Read More

jQuery Interactive Exercises: Enhance Web Interactivity

Exercise 1

Listing

Count
  • Record 1 Up Down Duplicate Delete
  • Record 2 Up Down Duplicate Delete
  • Record 3 Up Down Duplicate Delete

Plugin Code

    
(function($) {
  $.fn.up = function() {
    this.on("click", function() {
      $(".up").parent().insertBefore($(this).parent().prev());
    })
  }
  $.fn.down = function() {
    this.on("click", function() {
      $(this).parent().insertAfter($(this).parent().next());
    })
  }
  $.fn.duplicate = function() {
    this.on("click", function() {
      $(this).
Read More

IAM, BNS, BSYS, NSYS, and XRF Credentials Management

Hi XXX,

Regards,
Peru NT Administration (Mario Acosta)

IAM Credentials

  • QAT BNS: s5913113
  • IST BNS: s8003326
  • UATBNS: ou=Users_Groups,dc=Uatbns,dc=bns
  • UATBSYS: ou=Users,dc=Uatbsys,dc=bns
  • UATNSYS: ou=Users_Groups,dc=Uatnsys,dc=bns
  • TESTBNS: ou=Users_Group,dc=Testbns,dc=bns
  • ISTNB: ou=Users_Groups,dc=Istnb,dc=bns

URLs:

Active Directory:

  • AD-BNS: UATBNS TESTBNS
  • AD-BSYS: UATBSYS BCXISDOM
  • AD-NSYS: UATNSYS ISTNB

PV

PV: pru003 (SR1926pe)

iShare

iShare: 6447090 (5913113)
http://ishare.bns/

Windows

Read More

MFS File System Implementation: Data Structures and Functions


#include "block.h"
#include "mfs.h"
char filesystem_name[] = "my_mfs.img";

Data Structures

struct super_block {
    int block_size;
    int num_inodes;
    int num_bitmap;
    int num_data_blocks;
    int root_inode;
};
struct Extent {
    int start;
    int size;
};
struct disk_inode {
    int size;
    struct Extent e;
};
#define ENTRY_SIZE 14
struct entry {
    char name[ENTRY_SIZE];
    int is_dir;
    short inode;
};
struct

Read More

Python Code Examples: Permutations, Polynomials, and Matrices

Permuting Words

Iterative


from math import *

def Permuta(Cad):
    n = len(Cad)
    np = factorial(n)  # Total number of permutations
    l = [''] * np
    for num in range(n - 1, -1, -1):
        repe = factorial(num)
        pos = 0
        c = 0
        for k in range(len(l)):
            while Cad[pos] in l[k]:
                pos = pos + 1
                if pos >= n:
                    pos = 0
            l[k] = l[k] + Cad[pos]
            c = c + 1
            if c == repe:
         
Read More