#Nathan Fox #Homework 1 #I give permission for this work to be posted online #Help procedure Help:=proc() : print(`FindUPi(L,i), FindUP(L)`): end: #L: list of numbers #i: positive integer #If there exists a list M of length i such that L ends with #at least three repeated copies of M, returns M #Otherwise, returns FAIL #Works by checking if the last 3i elements of the list are #the same as the last i repeated 3 times FindUPi:=proc(L, i) local m, n: n:=nops(L): m:=L[n-i+1..]: if L[n-3*i+1..]=[op(m),op(m),op(m)] then m: else FAIL: fi: end: #L: list of numbers #If there exists a list M such that L ends with #at least three repeated copies of M, returns the shortest such M #Otherwise, returns FAIL #Works by calling FindUPi for all i values from 1 to #the length of L divided by 3 FindUP:=proc(L) local i, m, n: n:=nops(L): for i from 1 to n/3 do m:=L[n-i+1..]: if L[n-3*i+1..]=[op(m),op(m),op(m)] then return m: fi: end do: return FAIL: end: #Note: these procedures are not recursive, so we do not need option remember