Monday Mini-Golf: A series of short code-golf challenges, posted (hopefully!) every Monday.
I then proceeded to press the Execute button, and was surprised when it told me that the code I had entered was invalid. I took a second look at the textbox and saw this:
Wha??? That's not what I entered! So what happened here? To figure it out, I entered two simple lines:
This turned out as:
By now, I still had no clue about what happened to letters, but the numbers seemed simpler, so I took a closer look. As it turned out, the webpage was simply entering the first character, then repeating all the rest in the string every time a new one was pressed:
0112123123412345123456 0 1 12 123 1234 12345 123456
But what about the sections of letters? After pondering for a minute, I realized that it's just the same, but instead of repeating each subsection once, it repeats it twice:
abbbcbcbcdbcdbcdebcdebcdefbcdefbcdefgbcdefg a bb bcbc bcdbcd bcdebcde bcdefbcdef bcdefgbcdefg
A combination of the two works with a combination of these techniques:
abc123z abbbcbcbc1bc12bc123bc123zbc123z a bb bcbc bc1 bc12 bc123 bc123zbc123z
Whatever glitch causes this seems to reset at punctuation and spaces, so
abc def becomes
By this point, I was so absorbed in figuring it out and turning it into an interesting challenge that I forgot why I had been on there in the first place. (I did figure out how to type normally, however: pressing space-backspace after every character. Pretty tedious, but you gotta do what you gotta do.)
The goal of the challenge is to write a program or function that takes in the text to be processed, makes the changes listed above, and outputs/returns the result.
- The input will only contain printable ASCII, and no tabs or newlines.
Inputs: (one per line)
Mess up text This is some longer text. CAPS LOCK && "Punc-tua"+'tion' under_score_style CaPs wItHIn loWERs 1337 numb3r5 abcdefghij 0123456789 Code-golf is the best!
Meeesesessess upp teeexexextext Thhhihihishis iss sooomomomeome looononongongongeongeongeronger teeexexextext. CAAAPAPAPSAPS LOOOCOCOCKOCK && "Puuunununcunc-tuuuaua"+'tiiioioionion' unnndndndendendernder_scccococorcorcorecore_stttytytyltyltyletyle CaaaPaPaPsaPs wIIItItItHItHItHIItHIItHInItHIn loooWoWoWEoWEoWERoWERoWERsoWERs 1333337 nuuumumumbumbumb3umb3rumb3rumb3r5 abbbcbcbcdbcdbcdebcdebcdefbcdefbcdefgbcdefgbcdefghbcdefghbcdefghibcdefghibcdefghijbcdefghij 0112123123412345123456123456712345678123456789 Cooodododeode-gooolololfolf iss thhhehe beeesesestest!
This is code-golf, so shortest valid code in bytes wins. Tiebreaker goes to submission that reached its final byte count first.
The winner will be chosen next Monday, Nov 2. Good luck!
Edit: And the winner is... @MartinBüttner using Retina for an incredible 43-byte solution!
1 Yes, this story is completely true, and if you need any more clarification, see footnote 1.
' '.join(x+''.join(2*x[1:i]for i in range(1,len(x)+1)) for x in raw_input().split())\$\endgroup\$