Wow. This was a neat problem. I'd like to post my solution (which came in really abysmally) and
MeowChow's solution, which was the leader till this weekend. Just reading this one game me a ton of new tricks.
I managed to get to 92 characters with the following:
map$j{join'',sort/./g}.=$_,sort<>;map{/^[^a]/&&print$'}sort map{(a..t)
+[s!$/(?=.)! !g].$_}%j
I was miffed that I couldn't get to 80 or less, but it was better than the 120+ I originally had.
Then I looked at MeowChow's.
$o{_,sort/./g}=~s/.*/_$& $_/for sort<>;print/__ (.*
)/for sort%o
And, yes, that carriage return after the .* is necessary. I'm like, Ouch! The tricks in this one.
- I'd been struggling to remove the join in my hashkey. I couldn't figure out how to force stringification on the sort without having it hit scalar context first. I completely forgot to look at multiple keys.
- I started in with the GRT so I could get everything to work with the default behavior of sort. The problem was that I was setting some letter, then having to remove that letter. That cost me, easily, 6+ characters. Instead, just concatenate some character as many times as you have words at the beginning, then strip that out later.
The best thing about doing it this way is that you get to count while reading, instead of counting when preparing to write.
- I was stupid with the s!$/(?=.)! !g stuff. I forgot to use a carriage return within the substitution and didn't know how to use \b. *sighs*
For those curious why
MeowChow didn't do something with $' instead of adding the carriage return in the capture, remember that doing it that way would require two
map/
for's, not just one.
------
We are the carpenters and bricklayers of the Information Age.
Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.