#JUNIPER GREEN #VERY PRELIMINARY VERSION Help:=proc(): print(`M(n,P), e.g. M([10,[10,{}]);, WM(n,P), Wh(n,P), WMh(n,P) , mex(A) , G(n,P), Gh(n,P) `):end: with(numtheory): mex:=proc(A) local i: if A={} then RETURN(FAIL): fi: for i from 0 while member(i,A) do od:i:end: #EASY VERSION #M(n,P): All the legal moves in Juniper Green with starting integer n, P=[m,S], where m is current integer m and "already used set" S. Try: #M(10,[10,{}]); M:=proc(n,P) local m,S,i,S1,m1: option remember: m:=P[1]: S:=P[2]: if P[1]=n and S={} then S1:={seq(i,i=1..n)}: else S1:=divisors(m) union {seq(m*i,i=1..trunc(n/m))}: fi: S1:=S1 minus S: {seq([m1, S union {m1}],m1 in S1)}: end: #WM(n,P): The set of winning moves in Juniper-Green starting with n and current state P. Try: #WM(10,[10,{}]); WM:=proc(n,P) local gu,gu1,mu: option remember: gu:=M(n,P): if gu={} then RETURN({}): fi: mu:={}: for gu1 in gu do if WM(n,gu1)={} then mu:=mu union {gu1}: fi: od: mu: end: #G(n,P): The Sprague-Grundy value of position P in EASY Juniper Green with starting integer n G:=proc(n,P) local S,s: option remember: S:=M(n,P): if S={} then 0: else mex({seq(G(n,s),s in S)}): fi: end: #HARD VERSION #Mh(n,P): All the legal moves in Juniper Green Hard with starting integer n, P=[m,S], where m is current integer m and "already used set" S. Try: #Mh(10,[10,{}]); Mh:=proc(n,P) local m,S,i,S1,m1: option remember: m:=P[1]: S:=P[2]: if P[1]=n and S={} then S1:={seq(2*i,i=1..trunc(n/2))}: else S1:=divisors(m) union {seq(m*i,i=1..trunc(n/m))}: fi: S1:=S1 minus S: {seq([m1, S union {m1}],m1 in S1)}: end: #WMh(n,P): The set of winning moves in Juniper-Green starting with n and current state P. Try: #WMh(10,[10,{}]); WMh:=proc(n,P) local gu,gu1,mu: option remember: gu:=Mh(n,P): if gu={} then RETURN({}): fi: mu:={}: for gu1 in gu do if WMh(n,gu1)={} then mu:=mu union {gu1}: fi: od: mu: end: #Gh(n,P): The Sprague-Grundy value of position P in Hard Juniper Green with starting integer n Gh:=proc(n,P) local S,s: option remember: S:=Mh(n,P): if S={} then 0: else mex({seq(Gh(n,s),s in S)}): fi: end: