#John Kim #Use whatever you like #CS(n): Outputs the nth term mu(n) of the Sloane sequence CS:=proc(n) local L,start,count,next1,max,i,j: start:=[0$n]: max:=n: for i from 1 to 2^n-1 do L:=start+[2$n]: count:=n: next1:=nextElt(L): while(next1=2 or next1=3) do L:=[op(L),next1]: count:=count+1: next1:=nextElt(L): od: if count>max then max:=count: fi: start[n]:=start[n]+1: for j from 0 to n-1 do if start[n-j]>1 then start[n-j]:=0: start[n-j-1]:=start[n-j-1]+1: fi: od: od: max: end: #nextElt(L): Given a sequence L of 2s and 3s, outputs the largest number of repeating strings at the end of L. nextElt:=proc(L) local n,i,j,k,repSeq,compSeq,numRepSeq,maxRepSeq: n:=nops(L): maxRepSeq:=1: for i from 1 to n/2 do numRepSeq:=1: repSeq:=[seq(L[j],j=n-i+1..n)]: k:=n-i: while(k-i+1>0) do compSeq:=[seq(L[j],j=k-i+1..k)]: k:=k-i: if compSeq<>repSeq then break: else numRepSeq:=numRepSeq+1: fi: od: if numRepSeq>maxRepSeq then maxRepSeq:=numRepSeq: fi: od: maxRepSeq: end: