In quanti modi riusciamo a scrivere il crivello di Eratostene?
Gianluca Moro
giangiammy@gmail.com
Ven 29 Ott 2010 21:27:06 CEST
ciao,
TEST RUN:
bash-3.2$ ocaml
Objective Caml version 3.11.1
# let iota n =
let rec iotaIntern n =
match n with
| 2 -> [2]
| x -> x :: iotaIntern (n-1)
in List.rev (iotaIntern n)
in
let isMod b a = if a mod b == 0 then false else true
in
let rec primes l =
match l with
| [] -> []
| hd :: tl -> hd :: (primes (List.filter (isMod hd) tl) )
in
primes (iota 100)
;;
- : int list =
[2; 3; 5; 7; 11; 13; 17; 19; 23; 29; 31; 37; 41; 43; 47; 53; 59; 61; 67; 71;
73; 79; 83; 89; 97]
#
--
Gianluca Moro --- Enjoy CloudUSB: http://www.cloudusb.net/
http://www.giammy.com --- http://www.math.unipd.it/~giammy/
Diaspora Forum: http://diasporadoc.info/forum/
Just remember, there's a right way and a wrong way to do everything
and the wrong way is to keep trying to make everybody else do it the
right way
Maggiori informazioni sulla lista
blug