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
datatype 'label btree = | |
Empty | | |
Node of 'label * 'label btree * 'label btree; | |
fun lower(nil) = nil | |
| lower(c::cs) = (Char.toLower c)::lower(cs); | |
fun lt(x, y) = | |
implode(lower(explode(x))) < implode(lower(explode(y))); |
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 remove_a_stone vec i = | |
let | |
open VectorSlice | |
val size = Vector.length vec - 1 | |
val newvec = | |
if i = 0 then vector (slice (vec, 1, SOME size)) | |
else if i = size then vector (slice (vec, 0, SOME size)) | |
else concat [slice (vec, 0, SOME i), | |
slice (vec, i+1, SOME (size-i))] | |
in |
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 NotFoundException | |
fun get_primes n = | |
let | |
val l = List.tabulate (n, fn n => n + 2) | |
fun get_primes_sub nil result = result | |
| get_primes_sub (x::xs) result = | |
get_primes_sub (List.filter (fn n => n mod x <> 0) xs) (x::result) | |
in | |
List.rev (get_primes_sub l nil) |
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 sort _ nil = nil | |
| sort f (xl as x::xs) = sort f (List.filter (fn y => f y x = LESS) xs) | |
@ (List.filter (fn y => f y x = EQUAL) xl) | |
@ sort f (List.filter (fn y => f y x = GREATER) xs); | |
fun compare x y = | |
if x < y then LESS | |
else if x > y then GREATER | |
else EQUAL; |
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 subst src dst s = | |
let | |
open Substring | |
fun subst_sub src dst ss = | |
let | |
val (pref, suff) = position src ss | |
in | |
if isEmpty suff (* not found *) | |
then [pref] | |
else pref :: (full dst) :: |
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
open List;; | |
let generate_isprime x = | |
let rec generate_isprime x = | |
match x with | |
1 -> [] | |
| n -> n :: generate_isprime (n-1) | |
in | |
rev (generate_isprime x);; |
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
open List;; | |
open Int64;; | |
let binary_list_of_int n = | |
let rec binary_list_of_int n bit = | |
if bit = 1 then [n] | |
else (rem n (of_int 2)) :: binary_list_of_int (div n (of_int 2)) (bit-1) | |
in | |
binary_list_of_int n 32;; |
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
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.Scanner; | |
public class Asia2004A { | |
public static void main(String[] args) throws FileNotFoundException { | |
int a, b, d; | |
Scanner s = new Scanner(new File(args[0])); | |
while (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
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class Asia2005A { | |
public static void main(String[] args) throws FileNotFoundException { | |
boolean[] isprime = new boolean[10000]; | |
ArrayList<Integer> prime = new ArrayList<Integer>(); |
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 fib n = | |
let | |
fun fib1 1 = (1, 0) | |
| fib1 n = | |
let | |
val (l, m) = fib1 (n-1) | |
in | |
(l + m, l) | |
end | |
in |
OlderNewer