Re: [PHP] Re: [PHP-DEV] Anagram Type Puzzle
WHA - for school lessons ??? let's think about it ... - Original Message - From: Sebastian Bergmann [EMAIL PROTECTED] To: Ralph Guzman [EMAIL PROTECTED] Cc: PHP Developer Mailing List [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Monday, September 10, 2001 10:27 AM Subject: [PHP] Re: [PHP-DEV] Anagram Type Puzzle The list [EMAIL PROTECTED] is dedicated to the development _of_ PHP, not to developing _with_ PHP -- this is what the mailto:[EMAIL PROTECTED] list is for. I forward your message there, thanks for your understanding. Yours, Sebastian Ralph Guzman wrote: Im trying to figue out the following anagram using PHP. Here is the problem: Using letters of the alphabet represented by a number, I have to come up with words that add up to exactly 100. Numbers are in reverse where A=26 and Z=1, so for example: A = 26 B = 25 C = 24 ... ... X = 3 Y = 2 Z = 1 So let's say the word 'acronym' A + C+R+0+N+Y+M 26 + 24 + 9+12+13+2+14 = 100 My thoughts were to download a list of words in the dictionary, then read the file and somehow replace each letter by its number, then add each letter for each word and see which words would equal to 100. So I am emailing this list for any suggestions or examples of code that I can use to accomplish this. Any help? Thanks much. -- Sebastian Bergmann Measure Traffic Usability http://sebastian-bergmann.de/ http://phpOpenTracker.de/ Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Re: [PHP-DEV] Anagram Type Puzzle
Wow, that was a quick response! It's no wonder PHP kicks butt, when we have geniuses like you in the development team. I did not realize I sent it to the wrong list until after I had sent it. I apologize. I will try this now. Thanks a Million. -Original Message- From: James Moore [mailto:[EMAIL PROTECTED]] Sent: Monday, September 10, 2001 1:40 AM To: PHP Developer Mailing List; Ralph Guzman Cc: [EMAIL PROTECTED] Subject: [PHP] Re: [PHP-DEV] Anagram Type Puzzle This should really be sent to [EMAIL PROTECTED], this is the list for the developers OF PHP not developing WITH PHP. Anyway persuming you dictonary file has one word per line you could do somthing along the lines of the following: ?php $letters = array( A = 26, B = 25, C = 24, D = 23, E = 22, F = 21, G = 20, H = 19, . Z = 1); $word_array = file('en.dict'); foreach($word_array as $word) { $sum = 0; for($i = 0; $i strlen($word) and $sum = 100; $i ++ { $sum += $letters[strtoupper($word[$i])]; } if($sum == 100) { $correctwords[] = $word; } } echo Words that sum to 100\n; foreach($correctwords as $word) { echo $word.\n; } ? Im trying to figue out the following anagram using PHP. Here is the problem: Using letters of the alphabet represented by a number, I have to come up with words that add up to exactly 100. Numbers are in reverse where A=26 and Z=1, so for example: A = 26 B = 25 C = 24 ... ... X = 3 Y = 2 Z = 1 So let's say the word 'acronym' A + C+R+0+N+Y+M 26 + 24 + 9+12+13+2+14 = 100 My thoughts were to download a list of words in the dictionary, then read the file and somehow replace each letter by its number, then add each letter for each word and see which words would equal to 100. So I am emailing this list for any suggestions or examples of code that I can use to accomplish this. Any help? Thanks much. -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: [PHP-DEV] Anagram Type Puzzle
html body ?php $tab=array(a=26,b=25,c=24,d=23, e=22,f=21,g=20,h=19, i=18,j=17,k=16,l=15, m=14,n=13,o=12,p=11, q=10,r=9,s=8,t=7, u=6,v=5,w=4,x=3, y=2,z=1); $fid=fopen(testfile.txt,r); $line_num=0; while (!feof($fid)) { $line_num++; file://echo ligne : $line_num\nbr\n; $line = strtolower(fgets($fid,4096)); file://echo contenu de la ligne : $line\nbr\n; $words= explode( ,$line); while (list($foo,$word)=each($words)) { $word_value=0; for ($car=0;$carstrlen($word);$car++) { file://echo lettre : $word[$car] - \t; if ($letter_value=$tab[$word[$car]]) $word_value+=$letter_value; } file://echo mot : $word; ; file://echo valeur : $word_value\nbr\n; if ($word_value==100) echo the word b$word/b on line $line_value of the input file has a value of $word_value.br\n; } } echo br\nfont color=\red\If nothing appears above, no word with a value of 100 was found !!!\n; ? /body /html (°-Nayco, //\[EMAIL PROTECTED] v_/_ http://nayco.free.fr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Re: [PHP-DEV] Anagram Type Puzzle
Sorry, my F outlook replaced '//' commentaries by 'file://' ... these lines where for debugging, they can be deleted !!! - Original Message - From: nicolas costes [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, September 10, 2001 11:36 AM Subject: Re: [PHP] Re: [PHP-DEV] Anagram Type Puzzle html body ?php $tab=array(a=26,b=25,c=24,d=23, e=22,f=21,g=20,h=19, i=18,j=17,k=16,l=15, m=14,n=13,o=12,p=11, q=10,r=9,s=8,t=7, u=6,v=5,w=4,x=3, y=2,z=1); $fid=fopen(testfile.txt,r); $line_num=0; while (!feof($fid)) { $line_num++; file://echo ligne : $line_num\nbr\n; $line = strtolower(fgets($fid,4096)); file://echo contenu de la ligne : $line\nbr\n; $words= explode( ,$line); while (list($foo,$word)=each($words)) { $word_value=0; for ($car=0;$carstrlen($word);$car++) { file://echo lettre : $word[$car] - \t; if ($letter_value=$tab[$word[$car]]) $word_value+=$letter_value; } file://echo mot : $word; ; file://echo valeur : $word_value\nbr\n; if ($word_value==100) echo the word b$word/b on line $line_value of the input file has a value of $word_value.br\n; } } echo br\nfont color=\red\If nothing appears above, no word with a value of 100 was found !!!\n; ? /body /html (°-Nayco, //\[EMAIL PROTECTED] v_/_ http://nayco.free.fr -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]