blob: fba7f9661d474e3d5d0ea4c0a286b8890989570e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
(* Programmed by Jedidiah Barber *)
(* Licensed under the Sunset License v1.0 *)
let fibonacci ~len =
let rec fib a b r =
if List.length (r) > len - 1 then r
else fib b Z.(a + b) (a :: r)
in Array.of_list (List.rev (fib Z.zero Z.one []))
let pagoda ~len =
let open Z in
let rec b n =
if n = zero then zero
else (uneven n) / ~$2 mod ~$2
and a n =
if ~$n = zero then minus_one
else b (~$n + one) - b (~$n - one)
and uneven n =
if is_even n then uneven (n / ~$2) else n
in Array.init len a
let random ~len =
Random.self_init ();
let f n =
Z.of_int ((Random.int 1000000000) - 500000000)
in Array.init len f
|