48
3
Monday Mini-Golf: A series of short code-golf challenges, posted (hopefully!) every Monday.
True story1: The other day, I was playing around on my tablet when I had the idea to visit the page I normally use on my PC for testing JavaScript. After the page loaded, I entered this simple program:
alert("Hello!")
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:
alllelelerlerlertlert("Heeelelellellelloello!")
Wha??? That's not what I entered! So what happened here? To figure it out, I entered two simple lines:
abcdefg
0123456
This turned out as:
abbbcbcbcdbcdbcdebcdebcdefbcdefbcdefgbcdefg
0112123123412345123456
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 abbbcbc deeefef
.
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.)
Challenge
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.
Details
- The input will only contain printable ASCII, and no tabs or newlines.
Test-cases
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!
Outputs:
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!
Scoring
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.
1That punctuation rule...
' '.join(x[0]+''.join(2*x[1:i]for i in range(1,len(x)+1)) for x in raw_input().split())
– TheDoctor – 2015-10-27T14:26:23.067cough Use the Chrome DevTools cough – kirbyfan64sos – 2015-10-27T14:34:56.230
@TheDoctor Check out my answer's edit history :P – Beta Decay – 2015-10-27T15:10:44.483
1@BetaDecay great minds think alike ;) – TheDoctor – 2015-10-27T15:50:26.437
inb4 someone makes a language where you actually have to type like this. – DJgamer98 – 2015-11-06T12:46:47.507