Word Puzzle (Spoiler)
Mike Wey
mike-wey at example.org
Fri Aug 8 10:55:10 PDT 2008
On Thu, 2008-08-07 at 21:43 -0400, Wyverex wrote:
> "Take the names of two U.S. States, mix them all together, then
> rearrange the letters to form the names of two other U.S. States. What
> states are these?"
>
> Mark answers with (spoiler!)
>
>
> //All 50 states, lowercase, no spaces!!
> static char[][50] 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",
> "newhampshire","newjersey","newmexico","newyork","northcarolina",
> "northdakota","ohio","oklahoma","oregon","pennsylvania","rhodeisland",
> "southcarolina","southdakota","tennessee","texas","utah","vermont",
> "virginia","washington","westvirginia","wisconsin","wyoming"];
import tango.io.Stdout;
//All 50 states, lowercase, no spaces!!
static char[][50] 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",
"newhampshire","newjersey","newmexico","newyork","northcarolina",
"northdakota","ohio","oklahoma","oregon","pennsylvania","rhodeisland",
"southcarolina","southdakota","tennessee","texas","utah","vermont",
"virginia","washington","westvirginia","wisconsin","wyoming"];
void main()
{
char[][char[]] pairs;
for(int i = 0; i < states.length; i++)
{
for(int j = i; j < states.length; j++)
{
if( (states[i] ~ states[j]).sort in pairs)
Stdout(states[i])(" ")(states[j])(" -> ")
(pairs[(states[i] ~ states[j]).sort]).newline;
pairs[(states[i] ~ states[j]).sort] = states[i] ~" "~states[j];
}
}
}
> time ./states
> northdakota southcarolina -> northcarolina southdakota
>
> real 0m0.016s
> user 0m0.013s
> sys 0m0.003s
--
Mike Wey
More information about the Digitalmars-d-learn
mailing list