Skip to content

Instantly share code, notes, and snippets.

@blackh
Created February 2, 2012 08:53
Show Gist options
  • Save blackh/1722430 to your computer and use it in GitHub Desktop.
Save blackh/1722430 to your computer and use it in GitHub Desktop.
Colle 3
let rec suppri_list test l =
match (l, (if (l<>[]) then test (hd l) else false;)) with
| ([], _) -> []
| (_, true) -> suppri_list test (tl l)
| (_, false) -> (hd l)::(suppri_list test (tl l));;
suppri_list (modulo 2) (init 10);;
let modulo p n = ((n mod p)=0);;
let rec init n = match n with
2 -> [2]
| n -> n::(init (n-1));;
let rec er_aux l =
match l with
| [] -> []
|[x] -> [x]
| l -> (hd l)::(er_aux (suppri_list (modulo (hd l)) (tl l)));;
let eratos n =
let ent = rev(init n) in (er_aux ent);;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment