From: darren kirby Date: 2006-07-13T07:09:50+09:00 Subject: Re: [solution][QUIZ] Panagrams (#86) --nextPart1896260.BgATiusI6Z Content-Type: text/plain; charset="iso-8859-6" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for catching the "pangram" versus "panagram" issue, I had never noti= ced=20 it. Thanks to everyone for your great solutions, they are very interesting= =20 and I have learned a lot from reading them. In the interest of completeness, here is my original script that prompted m= e=20 to suggest this quiz. Those that read the Perl solution will recognize it i= s=20 very similar. This code is limited because (like the perl script) it will=20 barf if the count of any one letter is > 99, however, I have not found this= =20 to be a practical problem with any seeds I have tried (I think the greatest= =20 letter count was ~35). This code produced two solutions using the same seed, something I thought n= ot=20 possible (at least when using a reasonable short seed): Only a fool would check that this sentence contains exactly six 'a's, one '= b',=20 six 'c's, three 'd's, thirty-four 'e's, five 'f's, two 'g's, ten 'h's,=20 thirteen 'i's, one 'j', two 'k's, five 'l's, one 'm', twenty-two 'n's,=20 seventeen 'o's, one 'p', one 'q', seven 'r's, thirty-two 's's,=20 twenty-six 't's, three 'u's, seven 'v's, eight 'w's, six 'x's, seven 'y's,= =20 and one 'z'. and: Only a fool would check that this sentence contains exactly six 'a's, one '= b',=20 six 'c's, three 'd's, thirty-three 'e's, four 'f's, two 'g's, ten 'h's,=20 twelve 'i's, one 'j', two 'k's, six 'l's, one 'm', twenty 'n's, sixteen 'o'= s,=20 one 'p', one 'q', seven 'r's, thirty-two 's's, twenty-five 't's, three 'u's= ,=20 six 'v's, eight 'w's, seven 'x's, seven 'y's, and one 'z' And the code: ################# $snum =3D { 1 =3D> 'one', 2 =3D> 'two', 3 =3D> 'three', 4 =3D> 'four', 5 =3D> 'five= ', 6=20 =3D> 'six', 7 =3D> 'seven', 8 =3D> 'eight', 9 =3D> 'nine', 10 =3D> 'ten', 11 =3D> '= eleven', 12 =3D> 'twelve', 13 =3D> 'thirteen', 14 =3D> 'fourteen', 15 =3D> 'fift= een', 16 =3D> 'sixteen', 17 =3D> 'seventeen', 18 =3D> 'eighteen', 19 =3D> 'ni= neteen', 20 =3D> 'twenty', 30 =3D> 'thirty', 40 =3D> 'forty', 50 =3D> 'fifty', 6= 0=20 =3D> 'sixty', 70 =3D> 'seventy', 80 =3D> 'eighty', 90 =3D> 'ninety' } def spelledNumber(x) if x >=3D 100 print "must be 99 or less" exit elsif x <=3D 20 $snum[x] else tens =3D (x / 10).to_i * 10 if x - tens =3D=3D 0 $snum[x] else $snum[tens] + "-" + $snum[x - tens] end end end def checkIfTrue(s) realCount =3D {} LETTERS.each do |c| realCount[c] =3D s.count(c) end=20 if $fixedCount =3D=3D realCount puts "Found it:" puts s exit end $fixedCount.each do |key, value| x =3D s.count(key) y =3D value $fixedCount[key] =3D randomizer(x, y) end $fixedCount end def randomizer(x, y) if x =3D=3D y then return x end if x > y then x, y =3D y, x end rand(y-x+1)+x end=20 LETTERS =3D ('a'..'z').to_a seed =3D %q/darrens ruby panagram program found this sentence which contain= s=20 exactly and / $fixedCount =3D {} LETTERS.each { |c| $fixedCount[c] =3D rand(50) } while 1 (1..10000).each do s =3D seed LETTERS.each do |c| s +=3D spelledNumber($fixedCount[c]) s +=3D " '#{c}'" s +=3D $fixedCount[c] >=3D 2 ? "s, " : ", " end $fixedCount =3D checkIfTrue(s) end print "\t10K blip...\n" end ################### =2D-=20 darren kirby :: Part of the problem since 1976 :: http://badcomputer.org "...the number of UNIX installations has grown to 10, with more expected..." =2D Dennis Ritchie and Ken Thompson, June 1972 --nextPart1896260.BgATiusI6Z Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.4 (GNU/Linux) iD8DBQBEtXMMwPD5Cr/3CJgRAmefAKDikB6co/gqVVEAup14QJcsQiaByQCgyviB Czkk2hO3MzIyq3LHjyEmMf8= =lWcs -----END PGP SIGNATURE----- --nextPart1896260.BgATiusI6Z--