-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rabbits.oz~
59 lines (57 loc) · 1.21 KB
/
Rabbits.oz~
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
declare GetRefTime in GetRefTime = {Link ['x-oz://boot/Time']}.1.getReferenceTime
declare
fun {NaiveRabbit N}
if N == 0 then 2
elseif N == 1 then 4
elseif N == 2 then 8
else {NaiveRabbit N-1}+{NaiveRabbit N-2}+{NaiveRabbit N-3} end
end
fun {Rabbit N}
local
fun {RabbitLoop X N1 N2 N3}
if X == 0 then N1
else
{RabbitLoop X-1 N3+N2+N1 N1 N2}
end
end
in
case N
of 0 then 2
[] 1 then 4
[] 2 then 8
else {RabbitLoop N-3 8 4 2}
end
end
if N == 0 then 2
elseif N == 1 then 4
elseif N == 2 then 8
else {Rabbit N-1}+{Rabbit N-2}+{Rabbit N-3} end
end
fun {Measure N} %signature to provide
local T1 T2 T3 T4 NR1 NR2
in
T1 = {GetRefTime}
NR1 = {NaiveRabbit N}
T2 = {GetRefTime}
T3 = {GetRefTime}
NR2 = {Rabbit N}
T4 = {GetRefTime}
T2-T1-(T4-T3)
end
end
{Browse {NaiveRabbit 3}}
{Browse {NaiveRabbit 4}}
{Browse {NaiveRabbit 5}}
{Browse {NaiveRabbit 10}}
{Browse {Measure 10}}
{Browse {Measure 11}}
{Browse {Measure 12}}
{Browse {Measure 13}}
{Browse {Measure 14}}
{Browse {Measure 15}}
{Browse {Measure 16}}
{Browse {Measure 17}}
{Browse {Measure 18}}
{Browse {Measure 19}}
{Browse {Measure 20}}
{Browse {Measure 25}}