String and Text Manipulation:
Anagrams
Mathematica has a full suite of string manipulation commands. In
combination with pattern matching, list manipulation, and the large
range of other sophisticated built-in functions, these allow you
to write text manipulation programs from the simple to the sophisticated.
Here we write a short program to check if two sentences are anagrams
of one another.
Here are two candidate anagrams:
"That's one small step for a man, one
giant leap for mankind." -- Neil
Armstrong
The Anagram:
Thin man ran; makes a large stride, left planet,
pins flag on moon! On
to Mars!
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.
The Anagram:
In one of the Bard's best-thought-of tragedies,
our insistent hero,
Hamlet, queries on two fronts about how life turns rotten.
Define the function that checks for the validity of these claims.
It makes use of string manipulation commands and pattern matching,
and is defined so that it only accepts strings in its arguments.
Check the first candidate:
This is hardly to be believed, but AnagramQ has spoken.
The second candidate is truly amazing:
|