#C1.txt: ExpMath Class of Jan. 24, 2013
#Getting Started
Help:=proc() : print(` f2(n), fk(k,n), fS(S,n) `): end:
#z(): does absolutely nothing (which is better than most programs)
z:=proc(): end:
#f2(n): inputs an integer n and outputs 0 if
#n is a losing position (against a player who is
#more than five-year old and with an IQ>80)
#and 1 if it a winning position
#in a penny removing game, where a legal move
#consists of removing one or two pennies
#n->n-1 OR n-2
f2:=proc(n) option remember:
if n<=0 then
0:
elif f2(n-1)=1 and f2(n-2)=1 then
0:
else
1:
fi:
end:
#fk(k,n): inputs pos. integers k and n and outputs
#0 (1) if in a game of removing 1,2,...,k pennies
#is a losing (winning position)
fk:=proc(k,n) local i:
option remember:
if n<=0 then
0:
elif {seq(fk(k, n-i),i=1..k)}={1} then
0:
else
1:
fi:
end:
#fS(S,n): inputs a set of pos. integers S and
#an integer n and outputs
#0 (1) if in a game of removing a member of S pennies
#is a losing (winning position)
fS:=proc(S,n) local i:
option remember:
if n<=0 then
0:
elif {seq(fS(S, n-i),i in S)}={1} then
0:
else
1:
fi:
end: