#Yusra Naqvi: HW #11 #OK to post ################################################################################ #1 #CN(S):inputs a string of numbers and outputs the curling number CN:=proc(S) local SS,subS,i,k,co: co:=1: SS:=convert(S,string): for i from 1 to length(S) do subS:=substring(SS,-i..-1): for k from 1 to floor(length(S)/i) do if substring(SS,-k*i..-(k-1)*i-1)<>subS then break: fi: od: co:=max(co,k-1): od: end: ################################################################################ #All23(n): outputs all strings of length n consisting of 2s and 3s All23:=proc(n) local S,i,v: S[0]:={""}: for i from 1 to n do S[i]:={seq(cat("2",v), v in S[i-1])}union{seq(cat("3",v), v in S[i-1])}: od: S[n]: end: ################################################################################ #CS(n):inputs a positive integer n and outputs the number mu(n) CS:=proc(n) local StSet,i,S,mu: StSet:=All23(n): for i from 1 to 2^n do S:=StSet[i]: mu[i]:=n: while CN(S)<>1 do mu[i]:=mu[i]+1: S:=cat(S,CN(S)): od: od: max(seq(mu[i],i=1..2^n)): end: ################################################################################