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
fun duplicate(L) = | |
if L=nil then nil | |
else hd(L)::hd(L)::duplicate(tl(L)); |
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
fun divide nil = (nil, nil) | |
| divide (x::nil) = ([x], nil) | |
| divide (x::y::xs) = | |
let | |
val (ys, zs) = divide xs | |
in | |
(x::ys, y::zs) | |
end; |
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
fun count (x, nil) = 0 | |
| count (x, y::ys) = if x = y then 1 + count(x, ys) else count(x, 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
fun concat(s, t) = s ^ t; | |
fun concatList(L) = reduce(concat, | |
map(Char.toString, L); |
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
fun combine(nil) = nil | |
| combine([x]) = [(x, 0)] | |
| combine(x::y::zs) = (x,y)::combine(zs); |
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
exception BadN; | |
exception BadM; | |
fun comb(n,m) = | |
if n<0 then raise BadN | |
else if m<0 orelse m>n then raise BadM | |
else if m=0 orelse m=n then 1 | |
else comb(n-1, m) + comb(n-1, m-1); |
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
fun comb(n,m) = | |
if m=0 orelse m=n then 1 | |
else comb(n-1, m) + comb(n-1, m-1); |
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
fun collatz(n:int) = | |
if n = 1 then 1 | |
else if n mod 2 = 0 then collatz(n div 2) | |
else collatz(n * 3 + 1); | |
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
fun carlist(nil) = nil | |
| carlist(nil::xs) = carlist(xs) | |
| carlist((x::xs)::ys) = x::carlist(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
fun area1 1 = 1 | |
| area1 n = n * n + area1 (n-1); | |
fun area n = real (area1 n) / real (n * n * n); |