with(numtheory): Help := proc() if args = NULL then print(`SJ,CutCake,MCake,SeCo,SeBG`); print(``); print(`Followed Winning Ways chapter 1,2 and 5`); print(`SJ = Ski Jumper 3 by n with L on top`); print(`CutCake = CutCake, MCake = Maundy cake`); print(`SeCo = Seating Couples`); print(`SeBG = Seating Boys and Girls`); print(``); print(`Make sure to run this program with NuToFr !!!`); elif args = `CutCake` then print(`CutCake(m,n) , input an m by n (V by H) cake`); print(`Left cut vertical, right cut horizontal into two smaller`); print(`return value of the cake`); elif args = `MCake` then print(`MCake(m,n), input an m by n (V by H) cake`); print(`Left cut vertical, right cut horizontal`); print(`into equal number of smaller pieces`); print(`return value of the cake`); elif args = `SJ` then print(`SJ(n,L,R), input a 3 by n rectangle with`); print(`Left on the top row, L column from the left`); print(`and Right on the second row, R column from the left`); print(`Left has an option to jump over right if he is on top`); print(`of him`); print(`return the value of the game`); elif args = `SeCo` then print(`SeCo(A,n,B), input A,B is L or R,`); print(`n is the number of empty seat`); print(`The rule is left and right taking turn seating couples`); print(`left has a lady on the left, right has a lady on the right`); print(`no lady is allowed to seat next to gentleman`); print(`return the value of the game`); elif args = `SeBG` then print(`SeBG(A,n,B), input A,B is L or R,`); print(`n is the number of empty seat`); print(`The rule is left and right taking turn seating boys and girls`); print(`no people the same sex is allowed to seat next to each other`); print(`return the value of the game`); else print(`there is no help for`, args); fi: end: ################################################################# CutCake :=proc(m,n) local i,x,y: option remember: if m = 1 and n = 1 then return([0]): fi: if m = 1 then return([n-1]); fi: if n = 1 then return([-m+1]); fi: x := max(seq(op(SumGame(CutCake(m,i),CutCake(m,n-i))),i=1..floor(n/2))); y := min(seq(op(SumGame(CutCake(i,n),CutCake(m-i,n))),i=1..floor(m/2))); return(VG([{[x]},{[y]}])); end: MCake := proc(m,n) local x,y: option remember: if m = 1 and n = 1 then return([0]): fi: x := max(seq(op(MCake(m,i))*(n/i),i in divisors(n) minus {n})); y := min(seq(op(MCake(i,n))*(m/i),i in divisors(m) minus {m})); return(VG([{[x]},{[y]}])); end: SJ:= proc(n,L,R) option remember: if L<0 or R<0 or L>n or R>n then return(ERROR): fi: if L > R then return([n-L-R+1]): fi: if L = R then return(VG([{[n-L-R+1]},{[n-L-R+2]}])): fi: if L < R then return(VG([{SJ(n,L+1,R)},{SJ(n,L,R-1)}])):fi: end: SeCo := proc(A,n,B) option remember: if n < 0 then print(`n must be greater or equal to 0`); return(ERROR); elif n = 0 then if A = B then return(ERROR); else return([0]); fi: elif n =1 then return([0]); elif n = 2 then if A = L and B = L then return([-1]); elif A = L and B = R or A = R and B = L then return([0]); elif A = R and B = R then return([1]); fi: fi: if A = L and B = L then return(VG([{seq(SumGame(SeCo(A,i,L),SeCo(L,n-2-i,B)),i=1..n-3)}, {seq(SumGame(SeCo(A,i,R),SeCo(R,n-2-i,B)),i=0..n-2)}])); elif A = R and B = R then return(VG([{seq(SumGame(SeCo(A,i,L),SeCo(L,n-2-i,B)),i=0..n-2)}, {seq(SumGame(SeCo(A,i,R),SeCo(R,n-2-i,B)),i=1..n-3)}])); elif (A = L and B = R) or (A = R and B = L) then return(VG([{seq(SumGame(SeCo(L,i,L),SeCo(L,n-2-i,R)),i=1..n-2)}, {seq(SumGame(SeCo(L,i,R),SeCo(R,n-2-i,R)),i=0..n-3)}])); else print(`Bad input , A, B is either L or R`); return(ERROR); fi: end: SeBG := proc(A,n,B) option remember: if n < 0 then print(`n must be greater or equal to 0`); return(ERROR); elif (A <> L and A <> R) or (B <> L and B <> R) then print(`Bad input , A, B is either L or R`); return(ERROR); elif n = 0 then if A <> B then return("illegal"); else return([0]); fi: elif n =1 then if A <> B then return([0]); elif A = L and B = L then return([1]); elif A = R and B = R then return([-1]); fi: fi: if A = L and B = L then return(VG([{seq(SumGame(SeBG(L,i,L),SeBG(L,n-1-i,L)),i=0..n-1)}, {seq(SumGame(SeBG(L,i,R),SeBG(R,n-1-i,L)),i=1..n-2)}])); elif A = R and B = R then return(VG([{seq(SumGame(SeBG(R,i,L),SeBG(L,n-1-i,R)),i=1..n-2)}, {seq(SumGame(SeBG(R,i,R),SeBG(R,n-1-i,R)),i=0..n-1)}])); elif A <> B then return(VG([{seq(SumGame(SeBG(L,i,L),SeBG(L,n-1-i,R)),i=0..n-2)}, {seq(SumGame(SeBG(L,i,R),SeBG(R,n-1-i,R)),i=1..n-1)}])); fi: end: