An ambigram is a (non-blank) symbol that looks unchanged when the paper on which it is
written is rotated 180 degrees about the axis perpendicular to the surface
of the paper. We are given a word and want to change it
into an ambigram, by modifying or removing its letters.
We will restrict our word to uppercase letters. In the font we are using, -
H I N O S X Z look unchanged after rotation
-
M W look like each other after rotation
Some examples of ambigrams are "MOW", "XXXXXXXXXXX", "XMIWX", "HXHXHXHXHXH".
We want to make minimal changes to the given word to produce an ambigram. We will measure the cost of
changing by distance within the alphabet, so changing an 'F' to an 'H' would incur
a cost of 2, and changing an 'I' to an 'F' would cost 3. If we
keep changing a letter until we run off either end of the alphabet, the
letter disappears. (When a letter disappears, letters around it slide together.) So we can make a C disappear at a cost of 3, and can make
a 'T' disappear at a cost of 7.
Create a class Ambigram that contains a method ambiword that is given a String
word and that returns the ambigram that is the cheapest to construct from word.
Among equally cheap ambigrams, return the longest. If a tie still exists, return the contender that comes earliest alphabetically. A String with no characters is NOT an ambigram.
|