--> sequence blocks, words, used function ABC_Solve(sequence word, integer idx) integer ch, res = 0 if idx>length(word) then res = 1 -- or: res = length(word)>0 -- (if "" -> false desired) else ch = word[idx] for k=1 to length(blocks) do if used[k]=0 and find(ch,blocks[k]) then used[k] = 1 res = ABC_Solve(word,idx+1) used[k] = 0 if res then exit end if end if end for end if return res end function constant tests = {{{"BO","XK","DQ","CP","NA","GT","RE","TG","QD","FS", "JW","HU","VI","AN","OB","ER","FS","LY","PC","ZM"}, {"","A","BarK","BOOK","TrEaT","COMMON","SQUAD","CONFUSE"}}, {{"US","TZ","AO","QA"},{"AuTO"}}, {{"AB","AB","AC","AC"},{"abba"}}} for i=1 to length(tests) do {blocks,words} = tests[i] used = repeat(0,length(blocks)) for j=1 to length(words) do printf(1,"%s: %t\n",{words[j],ABC_Solve(upper(words[j]),1)}) end for end for