-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.mnl
70 lines (66 loc) · 1.69 KB
/
test.mnl
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
60
61
62
63
64
65
66
67
68
69
70
-- test.mnl
{ {extern "manool.org.18/std/0.6/all"} in
: let { AllocOpt = False } in
: let { N = 40; M = 80 } in
: let { G = 2 } in
: let
{ Display =
{ proc { B } as
: for { I = Range[N]$ } do
: do Out.WriteLine[] after
: for { J = Range[M]$ } do
Out.Write[{if B[I; J] <> 0 then "*" else " "}]
}
}
in
: var { B = {array N of: array M of 0} } in
-- initialization
B[19; 41] = 1
B[20; 40] = 1
B[21; 40] = 1
B[22; 40] = 1
B[22; 41] = 1
B[22; 42] = 1
B[22; 43] = 1
B[19; 44] = 1
-- end of initialization
/*Out.WriteLine["Before:"]; Display[B]*/
{ var { NextB = B } in
: repeat G do
: do {if ~AllocOpt then (B = NextB)' else {assign B = NextB; NextB = B}'}% after
: for { I = Range[N]$ } do
: var { Up = {if I <> 0 then I - 1 else (N - 1)$}; Down = {if I <> (N - 1)$ then I + 1 else 0} } in
: for { J = Range[M]$ } do
: var { Left = {if J <> 0 then J - 1 else (M - 1)$}; Right = {if J <> (M - 1)$ then J + 1 else 0} } in
: var
{ Count =
B[Up ; Left ] +
B[Up ; J ] +
B[Up ; Right] +
B[I ; Right] +
B[Down; Right] +
B[Down; J ] +
B[Down; Left ] +
B[I ; Left ]
}
in
NextB[I; J] =
{ if Count == 2 then B[I; J] else
: if Count == 3 then 1 else
0
}
}
/*Out.WriteLine["After " G " generations:"]; Display[B]*/
{ var { ExpectedB = {array N of: array M of 0} } in
ExpectedB[20; 39] = 1
ExpectedB[20; 40] = 1
ExpectedB[20; 41] = 1
ExpectedB[21; 39] = 1
ExpectedB[21; 42] = 1
ExpectedB[22; 39] = 1
ExpectedB[22; 43] = 1
ExpectedB[23; 40] = 1
ExpectedB[23; 42] = 1
Out.WriteLine[{if B == ExpectedB then "Success" else "Fail"}]
}
}