I'm fairly certain his works. (And for longer cases than you might imagine.)
Soma
Code:
#include <iostream>
#include <string>
static const unsigned long values[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101};
unsigned long mugprime
(
const std::string & f
)
{
unsigned long return_value(0);
for(std::string::const_iterator cursor(f.begin()), stop(f.end()); stop > cursor; ++cursor)
{
std::string::value_type character(*cursor);
if(isalpha(character))
{
return_value += values[static_cast<unsigned long>(toupper(character))];
}
}
return(return_value);
}
int main()
{
const char s1[] = "To be or not to be: that is the question; whether 'tis nobler in the mind to suffer the slings and arrows of outrageous fortune, or to take arms against a sea of troubles and by opposing, end them?";
const char s2[] = "Is a befitting quote from one of Shakespeare's greatest tragedies. But why won't Hamlet's inspiring motto toss our stubborn hero's tortuous battle for life, on one hand, and death, on another?";
unsigned long vs1(mugprime(s1));
unsigned long vs2(mugprime(s2));
std::cout << "The string are " << ((vs1 == vs2) ? "anagrams" : "not anagrams") << "!\n";
return(0);
}