-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.led
204 lines (150 loc) · 6.57 KB
/
test.led
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
LED sample program
Nelson Rushton, Texas Tech University
July 2014
A few simple test functions to start off:
/---------------------------------------------------------------
f(x,y) :=
33 if g2(x) < 1;
x*y if x >=1 & y > 0;
x+2*y otherwise
g2(x) := x^2+4
g3(x) := g2(x+2)
---------------------------------------------------------------/
Integer m is a *divisor* of n if there exists an integer k such
that k*m=n. An effective definition is as follows:
/---------------------------------------------------------------
divisor(m,n) iff
m=0 & n=0 or
~m=0 & n mod m = 0
---------------------------------------------------------------/
An integer is *even* 2 is a divisor of it.
/---------------------------------------------------------------
even(n) iff divisor(2,n)
---------------------------------------------------------------/
A number is *negative* if it is less than 0, and otherwise
it is *nonnegative*.
/---------------------------------------------------------------
negative(x) iff x < 0
nonnegative(x) iff ~negative(x)
---------------------------------------------------------------/
Integer n is *prime* if n>1 and n has no divisors in {2..n-1}
/---------------------------------------------------------------
prime(n) iff n>1 & noDivisors(n,2,n-1)
noDivisors(k,lowr,uppr) iff
lowr > uppr or
~divisor(lowr,k) & noDivisors(k,lowr+1,uppr)
---------------------------------------------------------------/
An integer k is *perfect* if it is the sum of its divisors in the
interval {1..k-1}.
We will write sumDivisors(k,L,U) for the sum of all divisors of
k in the interval [L,U].
/---------------------------------------------------------------
perfect(k) iff k = sumDivisors(k,1,k-1)
sumDivisors(k,L,U) :=
0 if L>U;
L+sumDivisors(k,L+1,U) if L<=U & divisor(L,k);
sumDivisors(k,L+1,U) otherwise
---------------------------------------------------------------/
A dummy test function for testing nested brackets
/- t(x) := {x,x+1} -/
If S is a set of numbers, write Sum(S) for the sum of the members
of S.
/---------------------------------------------------------------
Sum(S):=
0 if S={};
choose(S) + Sum(S\{choose(S)}) otherwise
---------------------------------------------------------------/
/- g() := 12 -/
A nullary function. Currently it must be defined with parens but
called without them. So, given the following definition, e.g.,
the expression g-4 would evaluate to 8.
/---------------------------------------------------------------
range(m,n) :=
{} if m>n;
{m} U range(m+1,n) otherwise
---------------------------------------------------------------/
A dummy test function for constant
/--
If x=((1,2),(2,3)) & y=((3,4),(4,5)) then h := {x,y}
Z:= 0 T := {(0,2),(3,2),(2,4),(`x,2)}
If even(2) then e := 2
positiveTen(x) := 0<x<11
If A1 = ((400,475),(500,475)) & A2 = ((400,425),(500,425)) & A3 = ((400,475),(400,425)) & A4 = ((500,475),(500,425)) then L:={A1,A2,A3,A4}
If
L1 = ((200,100),(200,400)) &
L2 = ((300,100),(300,400)) &
L3 = ((100,200),(400,200)) &
L4 = ((100,300),(400,300))
then
gridDisplay := {L1,L2,L3,L4}
Gamma :={}
gameOver iff 1>2
If ~gameOver then currentPlayer:=`x if even(|Gamma|); `o otherwise
--/
test for type system
/--
T1:=Int
T2:=Int*Int
T3:={1,2,3}
T4:=Int U Seq(Int) U Lambda
T5:=fSet((Int*Int))
T6:=(Int*Rat)*(Int*Rat)
T7:=fSet(fSet(Int))
T8:=fSet(fSet(Int))
--/
###########################################################################
The following functions are written by one of the students in Dr. Rushton's class.
They are used to test the performance of the interpreter.
#############################################################################
/---------------------------------------------------------------------------
player:= {1, 2}
cell:= {1..19}*{1..19}
move:= player*cell
Layout:= fSet(move)
State:= Layout*player*Nat*Nat
B:= 1
W:= 2
dirs:= {(0,1), (1,1), (1,0), (1,-1), (0,-1), (-1,-1), (-1, 0), (-1,1)}
---------------------------------------------------------------------------/
other(p) is the player that is not player p.
/------------------------------
other: player -> player
other(p):= B if p=W;
W if p=B
-------------------------------/
layout(S) is the layout of the game in state S.
/-----
layout: State -> Layout
layout(S):= S[1]
-----/
If u is a cell and v is a pair of integers, then vecAdd(u,v) is the pair equal to (u[1]+v[1], u[2]+v[2]).
/---------------------------------------------------------------------------
vecAdd: cell*(Int*Int) -> Int*Int
vecAdd(u,v):= (u[1]+v[1], u[2]+v[2])
---------------------------------------------------------------------------/
If n is an integer and v is a pair of integers, then vecMult(n,v) is the pair equal to (n*v[1],n*v[2]).
/---------------------------------------------------------------------------
vecMult: Nat*(Int*Int) -> Int*Int
vecMult(n,v):= (n*v[1],n*v[2])
---------------------------------------------------------------------------/
If m is a move, p is a player, and S is a state, captureSet(m,p,S) is the set of stones that, if they are in the layout of S, will be captured by executing move m in state S.
/---------------------------------------------------------------------------
captureSet: move*player*State->Layout
captureSet(m,p,S):= captureHelp(m,dirSet(m,S)) if p=other(m[1]);
{} otherwise
---------------------------------------------------------------------------/
If dSet is a set of directions, captureHelp(m,dSet) is the set of moves representing the stones in the directions of dSet that m could capture, provided the moves are in the layout of the current state.
/----------------------------
captureHelp: move*fSet(Int*Int) -> Layout
captureHelp(m,dSet):= { (other(m[1]),vecAdd(m[2],d)) | d in dSet } U {(other(m[1]),vecAdd(m[2],vecMult(2,d))) | d in dSet }
-----------------------------/
dirSet(m,S) is the set of directions in which move m makes captures in state S.
/---------------------------
dirSet: move*State -> fSet(Int*Int)
dirSet(m,S):= {d | d in dirs & capture(m,d,S)}
----------------------------/
If d is a pair of integers, capture(m,d,S) means that move m made a capture in the direction of cell vecAdd(m[2],d) in state S.
/---------------------------------------------------------------------------
capture: move*(Int*Int)*State -> Bool
capture(m,d,S) iff {(other(m[1]),vecAdd(m[2],d)), (other(m[1]),vecAdd(m[2],vecMult(2,d))), (m[1],vecAdd(m[2],vecMult(3,d)))} subeq layout(S)
---------------------------------------------------------------------------/