(CGSuite) //To get nimber: Petersenk("111|000",2).CanonicalForm //returns nimber of GP(3,2) with 1s on outside, 0s inside class Petersenk extends ImpartialGame var nodes; //grid of nodes var n; //size of cycle var k; //twist amount method Petersenk(a,b) if a is Grid then nodes:=a; n:=nodes.ColumnCount; elseif a is String then nodes:=Grid.ParseGrid(a,"01"); n:=nodes.ColumnCount; else nodes:=Grid(2,a);//first row is outer cycle, second row is inner cycle(s) for i from 1 to a do nodes[1,i]:=1; nodes[2,i]:=2; end end k:=b; end override method Options(Player player) options:=[]; for i from 1 to n do if nodes[1,i] == 1 then //outer cycle j:=1; newstate1:=nodes; newstate1[1,i]:=(newstate1[1,i]+1)%2; //flip this node newstate1[2,i]:=(newstate1[2,i]+1)%2; //flip connecting node in inner cycle //flip node to the left if i == 1 then newstate1[j,n]:=(newstate1[j,n]+1)%2; end if i != 1 then newstate1[j,i-1]:=(newstate1[j,i-1]+1)%2; end //flip node to the right if i == n then newstate1[j,1]:=(newstate1[j,1]+1)%2; end if i != n then newstate1[j,i+1]:=(newstate1[j,i+1]+1)%2; end if numZeros(newstate1) > numZeros(nodes) then options.Add(Petersenk(newstate1,k)); end end if nodes[2,i] == 1 then //inner cycle j:=2; newstate2:=nodes; newstate2[1,i]:=(newstate2[1,i]+1)%2; //flip this node newstate2[2,i]:=(newstate2[2,i]+1)%2; //flip connecting node in outer cycle //flip node to the left if i-k < 1 then newstate2[j,n+(i-k)]:=(newstate2[j,n+(i-k)]+1)%2; else newstate2[j,i-k]:=(newstate2[j,i-k]+1)%2; end //flip node to the right if i+k > n then newstate2[j,i+k-n]:=(newstate2[j,i+k-n]+1)%2; else newstate2[j,i+k]:=(newstate2[j,i+k]+1)%2; end //newstate:=makeNewState(2,i); if numZeros(newstate2) > numZeros(nodes) then options.Add(Petersenk(newstate2,k)); end end end return options; end method getGrid() return nodes; end method numZeros(g) count:=0; for i from 1 to g.RowCount do for j from 1 to g.ColumnCount do if g[i,j]==0 then count:=count+1; end end end return count; end end