This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*let A = [1;2;3] | |
* genSublists A will yield | |
* [[1]; [1; 2]; [1; 3]; [1; 2; 3];[2]; [2; 3]; [3]; []] *) | |
let rec gen list head = | |
match list with | |
[] -> [] | |
| first::rest -> let start = (head @ [first]) in | |
let rec append list = | |
match list with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(*checks for existence of (b,c)*) | |
let rec exists_bc(b,r) = | |
match r with | |
[] -> false | |
| (x,c)::tail -> (x == b) || exists_bc(b,tail);; | |
(*constructs the list of relations that must exist for element a*) | |
let rec create_ac(a,b,r) = | |
match r with | |
[] -> [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//checks for existence of (b,c) | |
let rec exists_bc(b,r) = | |
match r with | |
[] -> false | |
| (x,c)::tail -> (x == b) || exists_bc(b,tail);; | |
//constructs the list of relations that must exist for element a | |
let rec create_ac(a,b,r) = | |
match r with | |
[] -> [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Question: Generate all the possible combinations of the letters on the telephone keypads. Recursively. | |
* Basically, the product of N sets. | |
* e.g given 2,3. Valid combinations include (A,D),(A,E),(B,D)... | |
*/ | |
public class KeyPadCombinations { | |
/* | |
* Parameters | |
* numbers = the key pad #s index = the position of a letter for | |
* each number level = the position of the current number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec unZip list = | |
match list with | |
[] -> ([], []) | |
| (x, y)::rest -> | |
let (xs, ys) = unZip rest in | |
(x::xs, y::ys);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* The map function *) | |
let rec map fn list = | |
match list with []->[] | |
| n::ns -> fn n::map fn ns;; | |
(* The reduce function *) | |
let rec reduce fn id list = | |
match list with []->id | |
| n::ns->fn n (reduce fn id ns);; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Write a function val zip : 'a list * 'b list -> 'a * 'b list which accepts a | |
* pair of lists of the same length and returns a list of pairs. For example, | |
* zip([1; 2; 3], ['A'; 'B'; 'C']) should return the list of pairs [(1, 'A'); (2, | |
* 'B'); (3, 'C')]. You may assume that the 2 input lists are of the same length. | |
* (2 Points)*) | |
let rec zip (a,b) = | |
match (a,b) with | |
([],[]) -> [] | |
| ([],n::ns)-> [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hash_table = {}; | |
function check_dup(name){ | |
for(i = 0; i < name.length; i++){ | |
if(name[i] in hash_table){ | |
return false; | |
}else{ | |
hash_table[name[i]] = true; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function eu(a, b){ | |
if(a % b == 0){ | |
return b; | |
}else{ | |
return eu(b, a % b); | |
} | |
} | |
alert(eu(30,12)); |
NewerOlder