My friend and I have this game that we play with words. It is a fun pastime and it involves "canceling out" letters in a word until there is nothing left. I am really tired of him being so much faster than me at it, so it is your job to implement it and let me finally beat him. Obviously, since I have to make the program as easy to hide as possible, it has to be small as possible.
How does this game work?
The game is a pretty simple algorithm. It reduces a alphabetical string until it can't be reduced any further, thus making it a sort of hash. The actual game that we humans do is very hard to implement, but it can be simplified into the following algorithm:
You start by folding the alphabet in half and lining up the two pieces like such:
a b c d e f g h i j k l m z y x w v u t s r p q o n
Then, starting from the middle, you assign the positive integers to the top half and the negative to the bottom:
a b c d e f g h i j k l m 13 12 11 10 9 8 7 6 5 4 3 2 1 z y x w v u t s r p q o n -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
Then you take your string (we will be using
hello world) and ignoring any non-alphabetical characters, translate it:
h e l l o w o r l d 6 9 2 2 -2 -10 -2 -5 2 10
Then you sum the letter values. The ones that lined up in the earlier diagram (e.g.
o) will cancel out, while the others will add up.
sum(6 9 2 2 -2 -10 -2 -5 2 10 )=12
12 is the number for
b, so the hash of
hello world is
For a word that completely cancels out (e.g.
love), you output the "0 character":
-. Note that in the input,
- will still be disregarded. It only matters in the output.
If the number's magnitude is larger than 13, then you start doubling up on the
a's and the
z's You basically take as many
z's fit into the number and take whatever is left into the last letter like so:
code golf: 43.
a's and has 4 left over:
aaa 4: j result: aaaj
Hint: This part is basically
divmod except that it rounds toward zero, not
-infinity (e.g. -43 would become 3
z's and and a
-4 which is
Note: the dash does not come if the
z's fit in perfectly, only if it is exactly
- The hash is case insensitive
- Standard Loopholes are not allowed
- I/O can be in any format that isn't too outlandish, stdin, stdout, command-line arg, function, etc.
- This is code-golf so shortest size in bytes wins.
hello world --> b love --> - this is an example --> aak hello *&*(&(*&%& world --> b good bye --> ae root users --> zzs