Re: Anagram Type Puzzle

From: Date: Mon, 10 Sep 2001 08:39:33 +0000
Subject: Re: Anagram Type Puzzle
References: 1  Groups: php.dev php.general 
Request: Send a blank email to php-dev+get-65637@lists.php.net to get a copy of this message
This should really be sent to php-general@lists.php.net, 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: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#65637) next »