September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -2,7 +2,10 @@
|
|||
|
||||
This task is inspired by [http://drdobbs.com/windows/198701685 Mark Nelson's DDJ Column "Wordplay"] and one of the weekly puzzle challenges from Will Shortz on NPR Weekend Edition [http://www.npr.org/templates/story/story.php?storyId=9264290] 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 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 [https://tapestry.tucson.az.us/twiki/bin/view/Main/StateNamesPuzzle the Unicon Discussion Web] which includes several solutions with analysis. Several techniques may be helpful and you may wish to refer to [[wp:Goedel_numbering|Gödel numbering]], [[wp:Equivalence_relation|equivalence relations]], and [[wp:Equivalence_classes|equivalence classes]]. The basic merits of these were discussed in the Unicon Discussion Web.
|
||||
|
||||
|
|
|
|||
50
Task/State-name-puzzle/Phix/state-name-puzzle.phix
Normal file
50
Task/State-name-puzzle/Phix/state-name-puzzle.phix
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
constant states = {"Alabama", "Alaska", "Arizona", "Arkansas",
|
||||
"California", "Colorado", "Connecticut", "Delaware",
|
||||
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois",
|
||||
"Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana",
|
||||
"Maine", "Maryland", "Massachusetts", "Michigan",
|
||||
"Minnesota", "Mississippi", "Missouri", "Montana",
|
||||
"Nebraska", "Nevada", "New Hampshire", "New Jersey",
|
||||
"New Mexico", "New York", "North Carolina", "North Dakota",
|
||||
"Ohio", "Oklahoma", "Oregon", "Pennsylvania",
|
||||
"Rhode Island", "South Carolina", "South Dakota",
|
||||
"Tennessee", "Texas", "Utah", "Vermont", "Virginia",
|
||||
"Washington", "West Virginia", "Wisconsin", "Wyoming"},
|
||||
-- extras = {"New Kory", "Wen Kory", "York New", "Kory New", "New Kory"}
|
||||
extras = {"Slender Dragon", "Abalamara"}
|
||||
|
||||
function no_dup(sequence s)
|
||||
s = sort(s)
|
||||
for i=length(s) to 2 by -1 do
|
||||
if s[i]=s[i-1] then
|
||||
s[i] = s[$]
|
||||
s = s[1..$-1]
|
||||
end if
|
||||
end for
|
||||
return s
|
||||
end function
|
||||
|
||||
procedure play(sequence s)
|
||||
s = no_dup(s)
|
||||
destroy_dict(1) -- empty dict
|
||||
for i=1 to length(s)-1 do
|
||||
for j=i+1 to length(s) do
|
||||
string key = trim(sort(lower(s[i]&s[j])))
|
||||
object data = getd(key)
|
||||
if data=0 then
|
||||
putd(key,{{i,j}})
|
||||
else
|
||||
for k=1 to length(data) do
|
||||
integer {m,n} = data[k]
|
||||
if m!=i and m!=j and n!=i and n!=j then
|
||||
?{s[i],s[j],"<==>",s[m],s[n]}
|
||||
end if
|
||||
end for
|
||||
putd(key,append(data,{i,j}))
|
||||
end if
|
||||
end for
|
||||
end for
|
||||
end procedure
|
||||
play(states)
|
||||
?"==="
|
||||
play(states&extras)
|
||||
|
|
@ -4,68 +4,56 @@
|
|||
'Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, New Jersey, New Mexico,',
|
||||
'New York, North Carolina, North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina,',
|
||||
'South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia, Wisconsin, Wyoming'
|
||||
|
||||
parse arg xtra; !=! ',' xtra /*add optional (fictitious) names.*/
|
||||
@abcU='ABCDEFGHIJKLMNOPQRSTUVWXYZ'; !=space(!) /*!: the state list, no extra blanks*/
|
||||
deads=0; dups=0; L.=0; !orig=!; z=0; @@.= /*initialize some REXX variables. */
|
||||
|
||||
do de=0 for 2; !=!orig; @.= /*use original state list for each. */
|
||||
|
||||
do states=0 until !=='' /*parse until the cows come home. */
|
||||
parse var ! x ',' !; x=space(x) /*remove all blanks from state name.*/
|
||||
if @.x\=='' then do /*was state was already specified? */
|
||||
if de then iterate /*don't tell error if doing 2nd pass*/
|
||||
dups=dups+1 /*bump the duplicate counter. */
|
||||
say 'ignoring the 2nd naming of the state: ' x
|
||||
iterate
|
||||
end
|
||||
@.x=x /*indicate this state name exists. */
|
||||
y=space(x,0); upper y; yLen=length(y) /*get upper name with no spaces; Len*/
|
||||
|
||||
if de then do /*Is the firstt pass? Then process.*/
|
||||
do j=1 for yLen /*see if it's a dead─end state name.*/
|
||||
_=substr(y,j,1) /* _: is some state name character.*/
|
||||
if L._\==1 then iterate /*Count ¬ 1? Then state name is OK.*/
|
||||
say 'removing dead─end state [which has the letter ' _"]: " x
|
||||
deads=deads+1 /*bump number of dead─ends states. */
|
||||
iterate states /*go and process another state name.*/
|
||||
end /*j*/
|
||||
z=z+1 /*bump counter of the state names. */
|
||||
#.z=y; ##.z=x /*assign state name; and original. */
|
||||
end
|
||||
else do k=1 for yLen /*inventorize state name's letters. */
|
||||
_=substr(y,k,1); L._=L._+1 /*count each letter in state name. */
|
||||
end /*k*/
|
||||
|
||||
end /*states*/
|
||||
end /*de*/
|
||||
|
||||
say; do i=1 for z /*list state names in order given. */
|
||||
say right(i,9) ##.i /*show the index number, state name.*/
|
||||
end /*i*/
|
||||
|
||||
say; say z 'state name's(z) "are useable."
|
||||
@abcU= 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; !=space(!) /*!: the state list, no extra blanks*/
|
||||
deads=0; dups=0; L.=0; !orig=!; @@.= /*initialize some REXX variables. */
|
||||
z=0 /* [↑] elide dend─end (DE) states.*/
|
||||
do de=0 for 2; !=!orig /*use original state list for each. */
|
||||
@.=
|
||||
do states=0 by 0 until !=='' /*parse until the cows come home. */
|
||||
parse var ! x ',' !; x=space(x) /*remove all blanks from state name.*/
|
||||
if @.x\=='' then do /*was state was already specified? */
|
||||
if de then iterate /*don't tell error if doing 2nd pass*/
|
||||
dups=dups + 1 /*bump the duplicate counter. */
|
||||
say 'ignoring the 2nd naming of the state: ' x; iterate
|
||||
end
|
||||
@.x=x /*indicate this state name exists. */
|
||||
y=space(x,0); upper y; yLen=length(y) /*get upper name with no spaces; Len*/
|
||||
if de then do /*Is the firstt pass? Then process.*/
|
||||
do j=1 for yLen /*see if it's a dead─end state name.*/
|
||||
_=substr(y, j, 1) /* _: is some state name character.*/
|
||||
if L._ \== 1 then iterate /*Count ¬ 1? Then state name is OK.*/
|
||||
say 'removing dead─end state [which has the letter ' _"]: " x
|
||||
deads=deads + 1 /*bump number of dead─ends states. */
|
||||
iterate states /*go and process another state name.*/
|
||||
end /*j*/
|
||||
z=z+1 /*bump counter of the state names. */
|
||||
#.z=y; ##.z=x /*assign state name; also original.*/
|
||||
end
|
||||
else do k=1 for yLen /*inventorize letters of state name.*/
|
||||
_=substr(y,k,1); L._=L._ + 1 /*count each letter in state name. */
|
||||
end /*k*/
|
||||
end /*states*/ /*the index STATES isn't incremented*/
|
||||
end /*de*/
|
||||
call list /*list state names in order given. */
|
||||
say z 'state name's(z) "are useable."
|
||||
if dups \==0 then say dups 'duplicate of a state's(dups) 'ignored.'
|
||||
if deads\==0 then say deads 'dead─end state's(deads) 'deleted.'
|
||||
say
|
||||
sols=0 /*number of solutions found (so far)*/
|
||||
|
||||
do j=1 for z /*◄───────────────────────────────────────────────────────────────┐ */
|
||||
/*look for mix and match states. │ */
|
||||
do k=j+1 to z /* ◄─── state K, state J ►───────┘ */
|
||||
say /*[↑] look for mix and match states*/
|
||||
do j=1 for z /* ◄──────────────────────────────────────────────────────────┐ */
|
||||
do k=j+1 to z /* ◄─── state K, state J ►─────┘ */
|
||||
if #.j<<#.k then JK=#.j || #.k /*is the state in the proper order? */
|
||||
else JK=#.k || #.j /*No, then use the new state name. */
|
||||
|
||||
do m=1 for z; if m==j | m==k then iterate /*no state overlaps are allowed. */
|
||||
if verify(#.m,jk)\==0 then iterate /*is this state name even possible? */
|
||||
nJK=elider(JK,#.m) /*a new JK, after eliding #.m chars.*/
|
||||
|
||||
do m=1 for z; if m==j | m==k then iterate /*no state overlaps are allowed. */
|
||||
if verify(#.m, jk) \== 0 then iterate /*is this state name even possible? */
|
||||
nJK=elider(JK, #.m) /*a new JK, after eliding #.m chars.*/
|
||||
do n=m+1 to z; if n==j | n==k then iterate /*no overlaps are allowed. */
|
||||
if verify(#.n,nJK)\==0 then iterate /*is it possible? */
|
||||
if elider(nJK,#.n)\=='' then iterate /*any leftovers letters? */
|
||||
if verify(#.n, nJK) \== 0 then iterate /*is it possible? */
|
||||
if elider(nJK, #.n) \== '' then iterate /*any leftovers letters? */
|
||||
if #.m<<#.n then MN=#.m || #.n /*is it in the proper order?*/
|
||||
else MN=#.n || #.m /*we found a new state name.*/
|
||||
if @@.JK.MN\=='' | @@.MN.JK\=="" then iterate /*was it done before? */
|
||||
if @@.JK.MN\=='' | @@.MN.JK\=="" then iterate /*was it done before? */
|
||||
say 'found: ' ##.j',' ##.k " ───► " ##.m',' ##.n
|
||||
@@.JK.MN=1 /*indicate this solution as being found*/
|
||||
sols=sols+1 /*bump the number of solutions found. */
|
||||
|
|
@ -74,13 +62,15 @@ sols=0 /*number of solutions found
|
|||
end /*k*/
|
||||
end /*j*/
|
||||
say /*show a blank line for easier reading.*/
|
||||
if sols==0 then sols='No' /*use mucher gooder (sic) Englishings. */
|
||||
say sols 'solution's(sols) "found." /*display the number of solutions found*/
|
||||
if sols==0 then sols= 'No' /*use mucher gooder (sic) Englishings. */
|
||||
say sols 'solution's(sols) "found." /*display the number of solutions found*/
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
elider: parse arg hay,pins /*remove letters (pins) from haystack. */
|
||||
do e=1 for length(pins); p=pos(substr(pins,e,1), hay)
|
||||
if p==0 then iterate ; hay=overlay(' ',hay,p)
|
||||
do e=1 for length(pins); p=pos( substr( pins, e, 1), hay)
|
||||
if p==0 then iterate ; hay=overlay(' ', hay, p)
|
||||
end /*e*/ /* [↑] remove a letter from haystack. */
|
||||
return space(hay,0) /*remove blanks from the haystack. */
|
||||
return space(hay, 0) /*remove blanks from the haystack. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
list: say; do i=1 for z; say right(i, 9) ##.i; end; say; return
|
||||
s: if arg(1)==1 then return arg(3); return word(arg(2) 's', 1) /*pluralizer.*/
|
||||
|
|
|
|||
26
Task/State-name-puzzle/Zkl/state-name-puzzle.zkl
Normal file
26
Task/State-name-puzzle/Zkl/state-name-puzzle.zkl
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#<<< // here doc
|
||||
states:=("Alabama, Alaska, Arizona, Arkansas,
|
||||
California, Colorado, Connecticut, Delaware, Florida,
|
||||
Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas,
|
||||
Kentucky, Louisiana, Maine, Maryland, Massachusetts,
|
||||
Michigan, Minnesota, Mississippi, Missouri, Montana,
|
||||
Nebraska, Nevada, New Hampshire, New Jersey, New Mexico,
|
||||
New York, North Carolina, North Dakota, Ohio, Oklahoma,
|
||||
Oregon, Pennsylvania, Rhode Island, South Carolina,
|
||||
South Dakota, Tennessee, Texas, Utah, Vermont, Virginia,
|
||||
Washington, West Virginia, Wisconsin, Wyoming"
|
||||
/* Uncomment the next line for the fake states. */
|
||||
# ",New Kory, Wen Kory, York New, Kory New, New Kory"
|
||||
#<<<
|
||||
).split(",").apply("strip");
|
||||
|
||||
smap:=Dictionary();
|
||||
Utils.Helpers.pickNFrom(2,states).apply2('wrap(ss){ // 1225 combinations
|
||||
key:=(ss.concat()).toLower().sort()-" ";
|
||||
smap[key]=smap.find(key,List()).append(ss.concat(" + "));
|
||||
});
|
||||
|
||||
foreach pairs in (smap.values){ // 1224 keys
|
||||
// pairs=Utils.Helpers.listUnique(pairs); // eliminate dups
|
||||
if(pairs.len()>1)
|
||||
println(pairs.concat(" = ")) }
|
||||
Loading…
Add table
Add a link
Reference in a new issue