I owed the group a solution, so here is my final pre-New-York-name-spawning solution, and now I am going back to my current personal project, which is weaning off of TeX and ANT by means of Unicon. :)
The program terminates when it has found the answer, but it could continue looking with just a small change. I go out of my way to avoid big storage for the pairs (though in this case the storage wouldn’t be very big, anyway). Here’s what the output of 'time ./states6' looks like: -------------------------------------------------------- "North Carolina" "South Dakota" "North Dakota" "South Carolina" ./states6 9.91s user 0.07s system 74% cpu 13.346 total ------------------------------------------------------------------------------ link core procedure getStates() return ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", ## "District of Columbia", "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"] end procedure main () local the_words, the_chars, char_counts, it local i the_words := getStates () the_chars := '' every the_chars := the_chars ++ !the_words char_counts := make_char_counts (the_chars, the_words) it := find_it (the_chars, the_words, char_counts) | stop ("D'oh!") write (image (the_words[it[1][1]])) write (image (the_words[it[1][2]])) write (image (the_words[it[2][1]])) write (image (the_words[it[2][2]])) end # Make a table for quickly looking up character count for a given # character and 'word' index. procedure make_char_counts (the_chars, the_words) local char_counts, c, ord_c, i char_counts := list (126) every c := !the_chars do { ord_c := ord (c) every i := 1 to *the_words do { /char_counts[ord_c] := list (*the_words) char_counts[ord_c][i] := charcnt (the_words[i], c) } } return char_counts end # Generate pairs of numbers, starting with the first pair to come # after the given pair p. procedure pairs (n, p) local i, j every j := p[2] + 1 to n do suspend [p[1], j] every i := p[1] + 1 to n do every j := i + 1 to n do suspend [i, j] end procedure pair_pairs (n) local left_pair, right_pair every left_pair := pairs (n, [1, 1]) do every right_pair := pairs (n, left_pair) do suspend [left_pair, right_pair] end procedure satisfies (pair_pair, the_chars, char_counts) local c, ord_c, v, w, x, y every c := !the_chars do { ord_c := ord (c) v := char_counts[ord_c, pair_pair[1][1]] w := char_counts[ord_c, pair_pair[1][2]] x := char_counts[ord_c, pair_pair[2][1]] y := char_counts[ord_c, pair_pair[2][2]] v + w = x + y | fail } return end procedure find_it (the_chars, the_words, char_counts) local pp every pp := pair_pairs (*the_words) do if satisfies (pp, the_chars, char_counts) then return pp fail end -- Barry.SCHWARTZ ĉe chemoelectric punkto org http://chemoelectric.org Free stuff / Senpagaj varoj: http://crudfactory.com 'Democracies don't war; democracies are peaceful countries.' - Bush (http://www.whitehouse.gov/news/releases/2005/12/20051219-2.html)
pgpIVUjHYJQmq.pgp
Description: PGP signature
------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________ Unicon-group mailing list Unicon-group@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/unicon-group