MyWormSeq:=proc(N) local L, s, t, i, n, maxlist, maxsteps: maxsteps:=0: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL and s[2] > maxsteps then maxlist:=s[1]: maxsteps:=s[2]: fi: od: maxlist, maxsteps: end: #number of total moves NuTM:=proc(L) local Orb,L1: L1:=L: Orb:=[L]: while L1<>FAIL and not IsOld(Orb)[1] do L1:=V1(L1): Orb:=[op(Orb),L1]: od: if L1=FAIL then RETURN(FAIL,nops(Orb)-1): else RETURN(Orb,nops(Orb)-1): fi: end: WorstWorm:=proc(N) local L, s, t, i, n, maxlist, maxsteps: maxsteps:=0: L:=[seq(seq([NuTM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL and s[2] > maxsteps then maxlist:=s[1]: maxsteps:=s[2]: fi: od: maxlist, maxsteps: end: LegalWorms:=proc(N) local L, s, t, i, n, c: c:=0: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL then c:=c+1: fi: od: c: end: AllCycles:=proc(N) local L, S, s, t, i, n: S:={}: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL then S:=S union {s[1][1]}: fi: od: S: end: EquivCycles:=proc(N) local L, S, s, t, i, n: S:={}: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL then S:=S union {convert(s[1], set)}: fi: od: S: end: #Inputs x and {[x, y], ...}, returns [x, y], else returns FAIL. FindPair:=proc(x, S) local s: for s in S do if s[1] = x then return(s): fi: od: return(FAIL): end: AllCycleFreqs:=proc(N) local L, S, s, T, i, n: S:={}: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL then T:=FindPair(s[1][1], S): if T = FAIL then S:=S union {[s[1][1], 1]}: else S:=S minus {T} union {[T[1], T[2]+1]}: fi fi: od: S: end: EquivCycleFreqs:=proc(N) local L, S, s, T, i, n: S:={}: L:=[seq(seq([NuM([s[1], op(t[1..s[1]-1]), s[2], op(t[s[1]..nops(t)])])], s in [seq(seq([i,j], j=0..N-1-i), i=0..N-1)]), t in Comps(N, N-2))]: for s in L do if s[1] <> FAIL then T:=FindPair(convert(s[1], set), S): if T = FAIL then S:=S union {[convert(s[1], set), 1]}: else S:=S minus {T} union {[T[1], T[2]+1]}: fi fi: od: S: end: # modified procedures from class #V1(L):Inputs a sequence of non-neg. integers #and performs one step n Eric Angelini's #(see A151986)'s glass worms game V1:=proc(L) local i,k: k:=L[1]: if nops(L)la do od: true,[op(i..nops(L),L)]: end: #NuM(L): inputs a sequence of non-neg. integers and #outputs either the CYCLE,#MovesToGetThere #or FAIL,#MovesToGetThere NuM:=proc(L) local Orb,L1: L1:=L: Orb:=[L]: while L1<>FAIL and not IsOld(Orb)[1] do L1:=V1(L1): Orb:=[op(Orb),L1]: od: if L1=FAIL then RETURN(FAIL,nops(Orb)-1): else RETURN(IsOld(Orb)[2],nops(Orb)-1): fi: end: Comps:=proc(n,k) local L,S,b,S1,s1: option remember: if k=0 then RETURN({[]}): fi: S:={}: for b from 0 to n-1 do S1:=Comps(n,k-1): S:= S union {seq([op(s1),b], s1 in S1)}: od: S: end: