Help:=proc(): print(` Sphere(pi,k), flip(pi,i) `): print(`Ball(pi,k) , BFPF(pi), g(n), gSeq(N) `): end: #Burnt Pancakes #[[0,0],0,[1,1],0,[-1,0]] #c(o=-1) [t, BLANK, [..... t-1], BLANK, [.... t+1] #[[0,0],0,[-1,1],0,[1,-1]] flip:=proc(pi,i) local j: [seq(-pi[i+1-j],j=1..i),op(i+1..nops(pi),pi)]: end: #Ball(pi,k): all the permutations of distance #<=k from pi Ball:=proc(pi,k) local i,s: option remember: {seq(seq(s[1], s in Sphere(pi,i)),i=0..k)}: end: #Spehere(pi,k): all the permutations, followed #by the list of flips, distance k from pi #For example, Sphere([2,1],1); should #output {[[1,2],[2]]}; Sphere:=proc(pi,k) local S,i,n,baxter,s,Andrew,Nei,ne: option remember: n:=nops(pi): if k=0 then RETURN({[pi,[]]}): fi: if k=1 then RETURN({seq([flip(pi,i),[i]],i=1..n )}): fi: S:=Sphere(pi,k-1): baxter:={}: Andrew:=Ball(pi,k-1): for s in S do Nei:=Sphere(s[1],1): for ne in Nei do if not member(ne[1],Andrew) then baxter:=baxter union {[ne[1],[op(s[2]),op(ne[2])]]}: Andrew:=Andrew union {ne[1]}: fi: od: od: baxter: end: #BFPF(pi): inputs a permutation pi and #outputs ONE list of flips making it #[1, ..., nops(pi)] BFPF:=proc(pi) local n,i,S,s,susan: n:=nops(pi): susan:=[seq(i, i=1..n)]: for i from 0 to 300*n do S:=Sphere(pi,i): for s in S do if s[1]=susan then RETURN(s[2]): fi: od: od: FAIL: end: #g(n): the largest number of flips needed to sort any #stack of n burnt pancakes. g:=proc(n) local i,susan: susan:=[seq(i,i=1..n)]: for i from 0 while Sphere(susan,i)<>{} do od: i-1: end: #gSeq(N): the first N terms of the sequence g(n) Sloane A078942 gSeq:=proc(N) local i: [seq(g(i),i=1..N)]: end: