473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Need a string algorithm.

I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:

Lets try an example:

C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953

The end result of the word Corey is the number 256,953.

Can anyone get this working in php? It is some new code I want to run
on my website http://www.ckoogle.com

Apr 4 '07 #1
5 1290
CoreyWhite wrote:
I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:

Lets try an example:

C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953

The end result of the word Corey is the number 256,953.

Can anyone get this working in php? It is some new code I want to run
on my website http://www.ckoogle.com
$multiplier = 1;
$sum = 0;
for($i=0; $i<length($s); $i++) {
$c = substr($s, $i, 1);
$cv = strpos("ABCDEFGHIJKLMNOPQRSTUVWXY", $c);
$sum = $sum+$cv*$multiplier;
$multiplier *= 10;
}

N.B. This is untested code. The resulting numbers will not be unique;
consider the string "AN" (25) and "BE" (25).
Apr 4 '07 #2
CoreyWhite <Co********@gmail.comwrote:
I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:
C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953
The end result of the word Corey is the number 256,953.
// $my_word in [a-zA-Z] !!!
function codeMyWord($my_word) {
$word_coded = 0;
for ($i = 0; $i < strlen($my_word); $i++) {
$word_coded += (ord(strtoupper($my_word{$i})) - 64) * pow(10, $i);
}
return number_format($word_coded);
}
echo codeMyWord('CoreyWhite'); //-- 7,100,556,953
--
@@@@@
E -00 comme on est very beaux dis !
' `) /
|\_ =="
Apr 4 '07 #3
On 4 Apr 2007 13:59:30 -0700, "CoreyWhite" <Co********@gmail.com>
wrote:
>I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:

Lets try an example:

C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953

The end result of the word Corey is the number 256,953.

Can anyone get this working in php? It is some new code I want to run
on my website http://www.ckoogle.com
sounds like someone trolling for homework
really lame
Apr 5 '07 #4
oldami kirjoitti:
On 4 Apr 2007 13:59:30 -0700, "CoreyWhite" <Co********@gmail.com>
wrote:
>I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:

Lets try an example:

C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953

The end result of the word Corey is the number 256,953.

Can anyone get this working in php? It is some new code I want to run
on my website http://www.ckoogle.com

sounds like someone trolling for homework
really lame
Nah, he's just mad as a hat. We're talking about the guy who claims to
have solved the Da Vinci code.

--
Ra*********@gmail.com
"Olemme apinoiden planeetalla."
Apr 5 '07 #5
On Thu, 05 Apr 2007 07:58:47 +0300, Rami Elomaa
<ra*********@gmail.comwrote:
>oldami kirjoitti:
>On 4 Apr 2007 13:59:30 -0700, "CoreyWhite" <Co********@gmail.com>
wrote:
>>I need to assign all characters the values 1-26, and add them up in
the string, each time multiplying the next characters value by
10^string placement. It should look something like this:

Lets try an example:

C 3
O 150
R 1,800
E 5,000
Y 250,000
----------------
256,953

The end result of the word Corey is the number 256,953.

Can anyone get this working in php? It is some new code I want to run
on my website http://www.ckoogle.com

sounds like someone trolling for homework
really lame

Nah, he's just mad as a hat. We're talking about the guy who claims to
have solved the Da Vinci code.
Don't forget about the evul organization that has infiltrated his town
and is poisoning the drinking water...oh and "fish
liping"...ROTFL...boy that's just never gonna stop being funny. ^_^

--

Onideus Mad Hatter
mhm ¹ x ¹
http://www.backwater-productions.net
http://www.backwater-productions.net/hatter-blog
Hatter Quotes
-------------
"You're only one of the best if you're striving to become one of the
best."

"I didn't make reality, Sunshine, I just verbally bitch slapped you
with it."

"I'm not a professional, I'm an artist."

"Your Usenet blinders are my best friend."

"Usenet Filters - Learn to shut yourself the fuck up!"

"Drugs killed Jesus you know...oh wait, no, that was the Jews, my
bad."

"There are clingy things in the grass...burrs 'n such...mmmm..."

"The more I learn the more I'm killing my idols."

"Is it wrong to incur and then use the hate ridden, vengeful stupidity
of complete strangers in random Usenet froups to further my art?"

"Freedom is only a concept, like race it's merely a social construct
that doesn't really exist outside of your ability to convince others
of its relevancy."

"Next time slow up a lil, then maybe you won't jump the gun and start
creamin yer panties before it's time to pop the champagne proper."

"Reality is directly proportionate to how creative you are."

"People are pretty fucking high on themselves if they think that
they're just born with a soul. *snicker*...yeah, like they're just
givin em out for free."

"Quible, quible said the Hare. Quite a lot of quibling...everywhere.
So the Hare took a long stare and decided at best, to leave the rest,
to their merry little mess."

"There's a difference between 'bad' and 'so earth shatteringly
horrible it makes the angels scream in terror as they violently rip
their heads off, their blood spraying into the faces of a thousand
sweet innocent horrified children, who will forever have the terrible
images burned into their tiny little minds'."

"How sad that you're such a poor judge of style that you can't even
properly gauge the artistic worth of your own efforts."

"Those who record history are those who control history."

"I am the living embodiment of hell itself in all its tormentive rage,
endless suffering, unfathomable pain and unending horror...but you
don't get sent to me...I come for you."

"Ideally in a fight I'd want a BGM-109A with a W80 250 kiloton
tactical thermonuclear fusion based war head."

"Tell me, would you describe yourself more as a process or a
function?"

"Apparently this group has got the market cornered on stupid.
Intelligence is down 137 points across the board and the forecast
indicates an increase in Webtv users."

"Is my .sig delimiter broken? Really? You're sure? Awww,
gee...that's too bad...for YOU!" `, )
Apr 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: M | last post by:
Hi, I've searched through the previous posts and there seems to be a few examples of search and replacing all occurrances of a string with another string. I would have thought that the code...
14
by: msnews.microsoft.com | last post by:
How can I encrypt and decrypt string?
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
10
by: Nemok | last post by:
Hi, I am trying to write an additive encryption algorithm in C++ that will encrypt a text by adding a random numer to each character in a string. The code looks similar to this: for(int...
40
by: apprentice | last post by:
Hello, I'm writing an class library that I imagine people from different countries might be interested in using, so I'm considering what needs to be provided to support foreign languages,...
1
by: Charles | last post by:
Hi all, I need C# code for Implementing MD5 Algorithm.. Hope all would have heard of MD5 Algorith... Does any one have the C# coding for that Algorithm.. please Send... ITs URgent..... Thanks...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
3
by: Nick Valeontis | last post by:
Hi to all! I am writing an implentation of the a-star algorithm in c#. My message is going to be a little bit long, but this is in order to be as specific as possible. My question has nothing to...
14
by: S | last post by:
Any idea on how I would be able to do a search within C# that does ranges or words For example I want to search for Chicken in the string string s1 = "This is Great Chicken";
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.