Recent public codes are listed below. You can filter them by the following programming languages:
- view
- All
- Ada
- Assembler
- Assembler
- AWK (gawk)
- AWK (mawk)
- Bash
- bc
- Brainf**k
- C
- C#
- C++
- C++0x
- C99 strict
- CLIPS
- Clojure
- COBOL
- COBOL 85
- Common Lisp (clisp)
- D (dmd)
- Erlang
- F#
- Factor
- Falcon
- Forth
- Fortran
- Go
- Groovy
- Haskell
- Icon
- Intercal
- Java
- JavaScript (rhino)
- JavaScript (spidermonkey)
- Lua
- Nemerle
- Nice
- Nimrod
- Objective-C
- Ocaml
- Oz
- Pascal (fpc)
- Pascal (gpc)
- Perl
- Perl 6
- PHP
- Pike
- Prolog (gnu)
- Prolog (swi)
- Python
- Python 3
- R
- Ruby
- Scala
- Scheme (guile)
- Smalltalk
- SQL
- Tcl
- Text
- Unlambda
- VB.NET
- Whitespace
-
1 2 3
let rec gcd m n = if (n = 0) m else (gcd n (m mod n) );; Printf.printf "%d\n" (gcd 3 4);;
-
1 2 3
let rec gcd m n = if (n = 0) then m else (gcd n (m mod n) );; Printf.printf "%d\n" gcd 3 4;;
-
1 2 3
let rec gcd m n = if (n = 0) m else (gcd n (m mod n) );; Printf.printf "%d\n" gcd 3 4;;
-
1 2 3 4
let linear x = x;; let rec sum n m f = if n<m then ((f n)+(sum (n+1) m f)) else (f n);; Printf.printf "%d\n" (sum 1 100 linear);;
-
1 2
let linear x = x;; let rec sum n m f = if n<m then ((f n)+(sum (n+1) m f)) else (f n);;
-
1 2 3 4 5 6 7 8 9
(* Eliminate consecutive duplicates of list elements. *) let compress l = let rec compress_2 l e = match l with [] -> [e] | h::t -> if ( h = e ) then ( compress_2 t e )
...
-
1 2 3 4 5 6 7 8
let rec mycompare l1 l2 = match (l1,l2) with ([],[]) -> true | (h1::t1,h2::t2) -> if(h1 = h2) then (mycompare t1 t2) else false | (l1,l2) -> false ;;
...
-
1 2 3 4 5 6 7 8
let rec mycompare l1 l2 = match (l1,l2) with ([],[]) -> true | (h1::t1,h2::t2) -> if(h1 = h2) then (mycompare t1 t2) else false | (l1,l2) -> false ;;
...
-
1 2 3 4 5 6 7
let rec myreverse l = match l with [] -> [] | h::t -> ((myreverse t) @ [h]) ;; myreverse [1;2;3;4;5];;
-
1 2 3 4 5 6 7 8 9
let my_reverse l = List.rev l;; let rec my_reverse_2 l = match l with [] -> [] | h::t -> ( ( my_reverse_2 t ) @ [h] ) ;;
...
-
1 2 3 4 5 6
let rec mylength l = match l with [] -> 0 | h::t -> (1+(mylength t)) ;; Printf.printf "%d\n" (mylength [1;2;4;5;6;78]);;
-
1 2 3 4 5
let rec mylength l = match l with [] -> 0 | h::t -> (1+(mylength t)) ;;
-
1 2 3 4 5 6 7 8
exception Short_list;; let rec kthelement k l = match l with [] -> raise Short_list | h::t -> if ( k = 1 ) then h else ( kthelement (k - 1) t ) ;; Printf.printf "%d\n" (kthelement 4 [1;2;3;4;5;6;7;8]);;
-
1 2 3 4 5 6 7 8
exception Short_list;; let rec kthelement k l = match l with [] -> raise Short_list | h::t -> if ( k = 1 ) then h else ( kthelement (k - 1) t ) ;; Printf.printf "%d\n" (kthelement 0 [1;2;3;4;5;6;7;8]);;
-
1 2 3 4 5 6 7 8
exception Short_List;; let rec kthelement k l = match l with [] -> raise Short_list | h::t -> if ( k = 1 ) then h else ( kthelement (k - 1) t ) ;; Printf.printf "%d\n" (kthelement 0 [1;2;3;4;5;6;7;8]);;
-
1 2
let kthelement k l = (List.nth l k);; Printf.printf "%d\n" (kthelement 0 [1;2;3;4;5;6;7;8]);;
-
1 2
let kthelement k l = (List.nth l k);; Printf.printf "%d\n" (kthelement 7 [1;2;3;4;5;6;7;8]);;
-
1 2
let kthelement k l = (List.nth k l);; Printf.printf "%d\n" (kthelement 7 [1;2;3;4;5;6;7;8]);;
-
1 2 3 4 5 6 7 8 9
exception Empty_list;; let lastbutone l = (List.nth l ((List.length l) -1));; let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1
...
-
1 2 3 4 5 6 7 8 9
exception Empty_list;; let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1 | h1::h2::t -> lastbutone2 (h2::t) ;; Printf.printf "%d\n" (lastbutone2 [1;2;3;4]);;
-
1 2 3 4 5 6 7 8
exception Empty_list;; let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1 | h1::h2::t -> lastbutone2 (h2::t) ;;
-
1 2 3 4 5 6 7 8
exception Empty_list;; let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1 | h1::h2::t -> lastbutone (h2::t) ;;
-
1 2 3 4 5 6 7
let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1 | h1::h2::t -> lastbutone (h2::t) ;;
-
1 2 3 4 5 6 7 8 9
(* Problem 02: Find the last but one element of a list *) exception Empty_list;; let last_but_one l = ( List.nth l ((List.length l) - 2) );; let rec last_but_one_2 l = match l with [] -> raise Empty_list
...
-
1 2 3 4 5 6 7 8 9
exception Empty_list;; let lastbutone l = (List.nth l ((List.length l) -1));; let rec lastbutone2 l = match l with [] -> raise Empty_list | h::[] -> raise Empty_list | h1::h2::[] -> h1
...
-
1 2 3 4 5
exception Empty_list;; let lastbutone l = (List.nth l ((List.length l) -1));; Printf.printf "%d\n" (lastbutone [1;2;3]);;
-
1 2 3 4 5
exception Empty_list;; let lastbutone l = (List.nth l ((List.length l) -1));; Printf.printf "%s\n" (lastbutone [1;2;3]);;
-
1 2 3 4 5
exception Empty_list;; let my_lastbut1 l = (List.nth l ((List.length l) - 2));; Printf.printf "%s\n" (my_lastbut1 ["a";"b";"c"]);;
-
1 2 3 4 5
exception Empty_list;; let my_lastbut1 l = (List.nth l ((List.length l) - 2));; Printf.printf "%s\n" (mylastbut1 ["a";"b";"c"]);;
-
1 2 3 4 5
exception Empty_list;; let my_lastbut1 l = (List.nth l ((List.length) - 2));; Printf.printf "%s\n" (mylastbut1 ["a";"b";"c"]);;


