30
1
Create a cat program, a.k.a a program that takes an input and prints it.
...Except, the program will randomly take characters away from your input and print that instead.
Each character in the input should have generally equal odds to be removed with the program, though, as it is hard to make that, the odds for each character can vary by 10% at most.
Your program should take the input, then randomly remove characters from the input, then print that version again. (You can print with trailing newlines or other characters in case your language has to print newlines.)
If the input was BOOOWL
, it shouldn't remove all Os with an equal chance: each character (not unique) should be considered, so instead of every O combined having a 1/5 chance (for example), each O should have a 1/5 chance, so, instead of there being a 1/5 chance of BWL
, there should be a 1/5 chance of BOWL
, BOOWL
.
Input is restricted to STDIN or closest equivalent.
Each character must have a minimum of 10% and a maximum of 30% chance to be removed.
Each character's odds should be calculated individually.
You can use any component of your language supporting random actions, be it functions or something other.
Output must be through STDOUT or the closest equivalent. If your language does have STDOUT, do not output in any other way. If your language cannot output strings as text, use closest equivalent (C's character array output's OK here).
This is code golf. Shortest program wins.
4Should there always be between 10% and 30% chance for a specific character to be removed? Or is that just for the purpose of the example? – attinat – 2019-08-11T20:40:39.017
Is output as an array of character allowed? – Sok – 2019-08-11T20:50:39.600
2what do you mean by "sets of one character"? if the input is
BOWL OF SOUP
might all theO
's be deleted in one go? – roblogic – 2019-08-12T05:14:58.6671all answers thus far use a fixed 20% chance for a character to be removed. I'm not sure the question intent is for all characters to have the same odds. – Nzall – 2019-08-12T07:10:39.880
As long as the chance is within the 10% - 30% range, it's good. – Andrew – 2019-08-12T08:59:13.580
3
Output must be through STDOUT, as a text. Do not output a character array.
<-- I have a language that allows you to output a character array (it is flattened before output). Is that disallowed? How about languages like C, where a string is basically a character array? – Ismael Miguel – 2019-08-12T09:12:50.1401Use the closest equivalent. C's character array strings are OK, as they are the closest equivalent to text. – Andrew – 2019-08-12T09:20:40.880
Can I add trailing newline that wasn't in input? – val says Reinstate Monica – 2019-08-12T09:48:03.980
You specified that stdout must be used for output, bat said nothing about input. I assume that it's restricted to stdin only as well? – val says Reinstate Monica – 2019-08-12T10:05:24.257
1I'm confused by this line "so instead of every O combined having a 1/5 chance (for example), each O should have a 1/5 chance." – Jerry Jeremiah – 2019-08-14T01:19:57.800
1om nom nom nom nom – cat – 2019-08-14T22:17:07.347
friggen cat eating my input – Andrew – 2019-08-15T17:05:34.340