Re: [PHP] Anagram Solution in PHP

2001-09-11 Thread David Otton

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; $istrlen($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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Anagram Solution in PHP

2001-09-11 Thread nayco

maybe you forgot something like:

.
$letter=26-(ord($word[$i])-65);// excellent !!!
if (($letter1)||($letter26))
$letter=0;
$total+=$letter;



(°-Nayco,
//\[EMAIL PROTECTED]
v_/_ http://nayco.free.fr


- Original Message -
From: David Otton [EMAIL PROTECTED]
To: Ralph Guzman [EMAIL PROTECTED]
Cc: PHP General Mailing List [EMAIL PROTECTED]
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; $istrlen($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: [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] Anagram Solution in PHP

2001-09-10 Thread Ralph Guzman

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  B  C...X  Y  Z
26 25 24..3  2  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 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] Anagram Solution in PHP

2001-09-10 Thread Seb Frost

Sounds like you know exactly what you want to do :-)

1)  Obtain a text file, csv or whatever of a dictionary (easy enough -
www.google.com).
2)  Find the ascii values for a-z or A-Z, your choice.
3)  Read in a word at a time.
4)  Convert to upper or lower case to reflect part (2)
5)  Create a simple formula that converts the ascii codes into the range
1-26.
Something like ascii code of z - ascii code of letter + 1 should do the
trick.
6) add them all up.

simple.

- seb

-Original Message-
From: Ralph Guzman [mailto:[EMAIL PROTECTED]]
Sent: 10 September 2001 09:26
To: PHP General Mailing List
Subject: [PHP] Anagram Solution in PHP


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  B  C...X  Y  Z
26 25 24..3  2  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 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]


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.277 / Virus Database: 146 - Release Date: 05/09/2001

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.277 / Virus Database: 146 - Release Date: 05/09/2001


-- 
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] Anagram Solution in PHP

2001-09-10 Thread nayco

I tried that code this morning :

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++;
   $line = strtolower(fgets($fid,4096));
   $words= explode( ,$line);
   while (list($foo,$word)=each($words))
  {
  $word_value=0;
  for ($car=0;$carstrlen($word);$car++)
{
if ($letter_value=$tab[$word[$car]])
 $word_value+=$letter_value;
}
   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

- Original Message -
From: Ralph Guzman [EMAIL PROTECTED]
To: PHP General Mailing List [EMAIL PROTECTED]
Sent: Monday, September 10, 2001 10:25 AM
Subject: [PHP] Anagram Solution in PHP


 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  B  C...X  Y  Z
 26 25 24..3  2  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 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]