Anonymous user
State name puzzle: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, added a subroutine..
m (→{{header|REXX}}: added/changed comments and whitespace, added a subroutine..) |
|||
Line 1,559:
'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(!)
deads=0; dups=0; L.=0; !orig=!;
do de=0 for 2;
@.=
do states=0 by 0 until !==''
parse var ! x ',' !; x=space(x)
if @.x\=='' then do
say 'ignoring the 2nd naming of the state: ' x; iterate
@.x=x
z=z+1
#.z=y; ##.z=x
else
_=substr(y,k,1); L._=L._ + 1 /*count each letter in state name. */
end /*states*/
end
▲say; do i=1 for z /*list state names in order given. */
▲ say right(i,9) ##.i /*show the index number, state name.*/
▲ say; 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.'
sols=0 /*number of solutions found (so far)*/
say /*[↑] look for mix and match states*/
do j=1 for z /* ◄──────────────────────────────────────────────────────────┐ */
do k=j+1 to z /* ◄─── state K, state J ►─────┘
▲ 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. */
do n=m+1 to z; if n==j | n==k then iterate /*no overlaps are allowed. */
if verify(#.n, nJK) \==
if elider(nJK, #.n) \== ''
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
say 'found: ' ##.j',' ##.k " ───► " ##.m',' ##.n
@@.JK.MN=1 /*indicate this solution as being found*/
Line 1,629 ⟶ 1,617:
end /*j*/
say /*show a blank line for easier reading.*/
if sols==0 then sols= 'No'
say sols 'solution's(sols) "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)
end /*e*/ /* [↑] remove a letter from haystack. */
return space(hay, 0)
/*──────────────────────────────────────────────────────────────────────────────────────*/
list: say; do i=1 for z; say right(i, 9) ##.i; end; say; return
'''output''' when using the default input:▼
s: if arg(1)==1 then return arg(3); return word(arg(2) 's', 1) /*pluralizer.*/</lang>
<pre style="height:60ex">
removing dead─end state [which has the letter Z]: Arizona
|