How to resolve the algorithm State name puzzle step by step in the LiveCode programming language
How to resolve the algorithm State name puzzle step by step in the LiveCode programming language
Table of Contents
Problem Statement
Background This task is inspired by Mark Nelson's DDJ Column "Wordplay" and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [1] and originally attributed to David Edelheit. The challenge was to take the names of two U.S. States, mix them all together, then rearrange the letters to form the names of two different U.S. States (so that all four state names differ from one another). What states are these?
The problem was reissued on the Unicon Discussion Web which includes several solutions with analysis. Several techniques may be helpful and you may wish to refer to Gödel numbering, equivalence relations, and equivalence classes. The basic merits of these were discussed in the Unicon Discussion Web. A second challenge in the form of a set of fictitious new states was also presented.
Write a program to solve the challenge using both the original list of states and the fictitious list.
Comma separated list of state names used in the original puzzle: Comma separated list of additional fictitious state names to be added to the original (Includes a duplicate):
Let's start with the solution:
Step by Step solution about How to resolve the algorithm State name puzzle step by step in the LiveCode programming language
Source code in the livecode programming language
function pairwiseAnagrams X
if the optionkey is down then breakpoint
put the long seconds into T
put empty into itemsSoFar
repeat for each item W in X
put word 1 to -1 of W into W
if D[W] = 1 then next repeat
put 1 into D[W]
repeat for each item W2 in itemsSoFar
put W,W2 & cr after WPairs[sortChars(W & W2,true)]
end repeat
put W & comma after itemsSoFar
end repeat
repeat for each key K in WPairs
put empty into pairsSoFar
repeat for each line L in WPairs[K]
repeat for each line L2 in pairsSoFar
if item 1 of L is among the items of L2 or item 2 of L is among the items of L2 then next repeat
put L && "and" && L2 & cr after R
end repeat
put L & cr after pairsSoFar
end repeat
end repeat
put the long seconds - T
return char 1 to -2 of R
end pairwiseAnagrams
function sortChars X,lettersOnly
get charsToItems(X,lettersOnly)
sort items of it
return itemsToChars(it)
end sortChars
function charsToItems X,lettersOnly
repeat for each char C in X
if lettersOnly and C is not in "abcdefghijklmnopqrstuvwxyz" then next repeat
put C & comma after R
end repeat
return char 1 to -2 of R
end charsToItems
function itemsToChars X
replace comma with empty in X
return X
end itemsToChars
You may also check:How to resolve the algorithm Empty string step by step in the Racket programming language
You may also check:How to resolve the algorithm Scope modifiers step by step in the ALGOL 60 programming language
You may also check:How to resolve the algorithm Pragmatic directives step by step in the 6502 Assembly programming language
You may also check:How to resolve the algorithm Modular inverse step by step in the zkl programming language
You may also check:How to resolve the algorithm Execute a system command step by step in the ABAP programming language