# Matthew Russell # Experimental Math # Homework 22 # I give permission to post this read `public_html/em12/split.txt`: ##################################################################################### # Using split(w1,w2), that returns true if and only if w1w2 splits into w1.w2, write a procedure # SplitUp(L), # that inputs a list in {1,2,3}*, L, # and outputs it as a list of lists # [L1,L2,L3, ...] # where L=[op(L1),op(L2), op(L3), ...] # and L1,L2,L3, are atoms. SplitUp:=proc(L) local K,pos,i,j,k,flag: option remember: K:=[]: pos:=1: for i from 1 to nops(L) do flag:=true: for j from i to nops(L) while flag do for k from j+1 to nops(L) do if split([op(i..j,L)],[op(j+1..k,L)]) and SplitUp([op(j+1..nops(L),L)])[1]=[op(j+1..k,L)] then K:=[op(K),[op(i..j,L)]]: i:=j: pos:=j+1: flag:=false: break: fi: od: od: od: return [op(K),[op(pos..nops(L),L)]]: end: