Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
24
Task/Hamming-numbers/OCaml/hamming-numbers-1.ocaml
Normal file
24
Task/Hamming-numbers/OCaml/hamming-numbers-1.ocaml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
module ISet = Set.Make(struct type t = int let compare=compare end)
|
||||
|
||||
let pq = ref (ISet.singleton 1)
|
||||
|
||||
let next () =
|
||||
let m = ISet.min_elt !pq in
|
||||
pq := ISet.(remove m !pq |> add (2*m) |> add (3*m) |> add (5*m));
|
||||
m
|
||||
|
||||
let () =
|
||||
|
||||
print_string "The first 20 are: ";
|
||||
|
||||
for i = 1 to 20
|
||||
do
|
||||
Printf.printf "%d " (next ())
|
||||
done;
|
||||
|
||||
for i = 21 to 1690
|
||||
do
|
||||
ignore (next ())
|
||||
done;
|
||||
|
||||
Printf.printf "\nThe 1691st is %d\n" (next ());
|
||||
25
Task/Hamming-numbers/OCaml/hamming-numbers-2.ocaml
Normal file
25
Task/Hamming-numbers/OCaml/hamming-numbers-2.ocaml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
open Big_int
|
||||
|
||||
module APSet = Set.Make(
|
||||
struct
|
||||
type t = big_int
|
||||
let compare = compare_big_int
|
||||
end)
|
||||
|
||||
let pq = ref (APSet.singleton (big_int_of_int 1))
|
||||
|
||||
let next () =
|
||||
let m = APSet.min_elt !pq in
|
||||
let ( * ) = mult_int_big_int in
|
||||
pq := APSet.(remove m !pq |> add (2*m) |> add (3*m) |> add (5*m));
|
||||
m
|
||||
|
||||
let () =
|
||||
let n = 1_000_000 in
|
||||
|
||||
for i = 1 to (n-1)
|
||||
do
|
||||
ignore (next ())
|
||||
done;
|
||||
|
||||
Printf.printf "\nThe %dth is %s\n" n (string_of_big_int (next ()));
|
||||
Loading…
Add table
Add a link
Reference in a new issue