L
LeQuestionnaire
Guest
I'm trying to write a script that does, for example, the following:
Takes a string, perhaps it's ABCD, and returns the sum of the position of each individual character in the alphabet (e.g. A = 1), but with a twist. As the script runs through the string, adding the corresponding numerical value of each character to the total of all the ones before it, it will check to see if the character's position in the alphabet is less than that of the character who's position in the string is right in front of it, and if so, then subtract instead of add.
For example, what I'd return for the string "ABCD" is -2, because - 1 - 2 - 3 + 4 = -2. For the string "ACDB", I'd return 2 because - 1 - 3 + 4 + 2 = 2.
This would make for a pseudo-random number generator whose "random" number actually corresponds to the seed string, but I've been messing with this for ages and I just can't get it to work. Help?
Takes a string, perhaps it's ABCD, and returns the sum of the position of each individual character in the alphabet (e.g. A = 1), but with a twist. As the script runs through the string, adding the corresponding numerical value of each character to the total of all the ones before it, it will check to see if the character's position in the alphabet is less than that of the character who's position in the string is right in front of it, and if so, then subtract instead of add.
For example, what I'd return for the string "ABCD" is -2, because - 1 - 2 - 3 + 4 = -2. For the string "ACDB", I'd return 2 because - 1 - 3 + 4 + 2 = 2.
This would make for a pseudo-random number generator whose "random" number actually corresponds to the seed string, but I've been messing with this for ages and I just can't get it to work. Help?