65
18
I wrote some text, but it looks too professional. I want to make it look like I was really tired when I wrote it. I need you to insert some typos.
Your challenge is to take an arbitrary single line of text, and add typos. This means that for each character, there will be a 10% chance for it to be typofied.
The definition of "typofied" is that you must choose (randomly) one of the following:
- Duplicate the character.
- Delete the character.
Shift the character one keyboard space. The "keyboard" is defined as:
qwertyuiop asdfghjkl zxcvbnm
For the character shift, you must go one space up, down, left, or right. This must be chosen randomly. The shift option only applies to alphabetic characters. Case must be preserved. Be careful with edge-cases, like
m
!
The definition of "random" is that the result must not be predictable (by looking at previous results). For example, you can't typofy every tenth character. Furthermore, the randomness must have an even distribution. For example, you can't do 30% duplicate, 30% delete, and 40% shift; it has to be a 1/3 chance for each (1/2 for each if it's a nonalphabetic character).
Example input:
This is some correct text. It is too correct. Please un-correctify it.
Example output:
This iissome xorreect tex.. It is too coteect. Please jn-corretify it.
This is code-golf, so the shortest code in bytes will win.
So if M is shifted, it has a 50% chance to be N and a 50% chance to be K? – Paul Prestidge – 2014-02-09T22:32:14.520
@Chron Correct. – Doorknob – 2014-02-09T22:44:09.003
From your example input/output I assume that Space counts as a character that can be duplicated and deleted, but not shifted. Also are capitals to be preserved? – Xantix – 2014-02-09T23:03:15.443
@Xantix Yes to both. – Doorknob – 2014-02-09T23:05:31.027
Wish I remembered more TECO; being a terse language specifically for editing, I suspect it could be a winner here. – keshlam – 2014-02-09T23:56:04.523
4What about accidentally striking the capslock key? When one types an "A" or "Z", there should be a random chance that they will hit capslock instead, ND END UP LIKE THIS. – AJMansfield – 2014-02-10T01:10:32.433
3@AJMansfield Lol, that would probably be too complicated. It's already complicated enough as it is :P – Doorknob – 2014-02-10T01:12:13.013
I have accidentally typed ',' instead of 'm' before. – None – 2014-02-10T03:20:50.790
1@user2509848 Hey, stop ,aking it ,ore co,plicated than it already is! :-P – Doorknob – 2014-02-10T03:40:35.020
OK, I guess we would then have to add numbers and other keyboard characters. – None – 2014-02-10T03:43:58.000
1@Doorknob Your example output doesn't look like you were tired, it looks like you're new to typing and you don't know how to correct typos. (Or you didn't look over what you'd typed at all.) – Blacklight Shining – 2014-02-10T04:42:32.157
Hmmmmmmmm http://codegolf.stackexchange.com/questions/12340/make-stackoverflow-explode-bookmarklet/12390#12390
– Sumurai8 – 2014-02-10T09:29:35.747@Blacklight Heh, that works too. :-P – Doorknob – 2014-02-10T12:47:47.953
@Sumurai Oooh, maybe that could be adapted for this challenge and used here! – Doorknob – 2014-02-10T12:48:45.323
Can strings be arbitrarily large after execution? I mean, if I duplicate a character, when I move on, am I going to reroll on that duplicate and maybe duplicate again, or go through to the next one. That is, is the size of the output string bounded by 2n? – Cruncher – 2014-02-10T16:10:44.627
@Cruncher No; after duplicating a character you do not reconsider the duplicated character. – Doorknob – 2014-02-10T19:13:59.203
1"edge-cases" <-- I see what you did there. *slow clap* – Adam Maras – 2014-02-12T23:52:58.013