#April 4, 2022, C20.txt Help20:=proc(): print(` P12(n), PR(n,R), LP(N,R) `):end: #PILE Of pennies , so the STATE of the game is the "number of pennies" #LEGAL MOVE: REMOVE ONE OR TWO PENNIES #YOU LOST IF there is no pennies: # #****** #*** #WE WANT A FUNCTION THAT INPUTS n and outputs 1 if is a winning position and 0 if it a losing position #ALSO THE WINNING MOVE # #P12(n): 1-pile Nim with {1,2} removal P12:=proc(n) local i,S: option remember: S:={}: for i from 1 to min(2,n) do if P12(n-i)[1]=0 then S:=S union {i}: fi: od: if S={} then 0,S: else 1,S: fi: end: #PR(n,R): Inputs a pos. integer n and a set of POSITIVE integers R #outputs 0,{} or 1,S where 0 means losing and S is the set of winning moves PR:=proc(n,R) local i,S: option remember: S:={}: for i in R do if i<=n and PR(n-i,R)[1]=0 then S:=S union {i}: fi: od: if S={} then 0,S: else 1,S: fi: end: # #LP(N,R): Inputs a pos. integer N and a removal set R outputs the #list of losing positions <=N LP:=proc(N,R) local L,i: L:=[]: for i from 1 to N do if PR(i,R)[1]=0 then L:=[op(L),i]: fi: od: L: end: