Re: Anagram Solution in PHP

From: Date: Tue, 11 Sep 2001 12:50:24 +0000
Subject: Re: Anagram Solution in PHP
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-66922@lists.php.net to get a copy of this message
maybe you forgot something like: ..... $letter=26-(ord($word[$i])-65); // excellent !!! if (($letter<1)||($letter>26)) $letter=0; $total+=$letter; .... (°- Nayco, //\ Nayco@netcourrier.com v_/_ http://nayco.free.fr ----- Original Message ----- From: David Otton <david.otton@overnetdata.com> To: Ralph Guzman <raguzman@netraiser.com> Cc: PHP General Mailing List <php-general@lists.php.net> Sent: Tuesday, September 11, 2001 2:32 PM Subject: Re: [PHP] Anagram Solution in PHP > On Mon, 10 Sep 2001 01:25:36 -0700, you wrote: > > >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? > > function total ($word) { > $total = 0; > $word = strtoupper($word); > for ($i=0; $i<strlen($word); $i++) { > $total+=26-(ord($word[$i])-65); > } > return($total); > } > > echo total('acronym'); > > djo > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#66922) next »