The cat ate your input again!

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.

Andrew

Posted 2019-08-11T11:03:02.137

Reputation: 2 067

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 the O's be deleted in one go? – roblogic – 2019-08-12T05:14:58.667

1all 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

3Output 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.140

1Use 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

Answers

10

Japt -f, 2 bytes

The -f flag "runs the program on each element in the first input, outputting an array of those that return a truthy value." returns a random number between 0(inclusive) and 5(exclusive). Like JavaScript, 0 is falsy in Japt.

Try it

Embodiment of Ignorance

Posted 2019-08-11T11:03:02.137

Reputation: 7 014

2I'm going back in time, making a language where o is this challenge and then going back and submitting my answer, or maybe make the empty string that :p – Andrew – 2019-08-12T09:36:03.693

Aren't commandline flags supposed to count towards bytecount? – Daniel Vestøl – 2019-08-14T05:37:06.810

1

@DanielVestøl Click on the -f, in the title.

– Ismael Miguel – 2019-08-14T09:19:56.437

1

@Andrew Using a made-up language specifically designed for the challenge

– Jo King – 2019-08-15T01:06:50.897

1was joke but ok – Andrew – 2019-08-15T16:48:14.243

8

Python 3, 63 bytes

from random import*
for c in input():print(end=c[random()<.2:])

Try it online!

Python 2, 67 65 bytes

from random import*
print''.join(c for c in input()if.8>random())

Try it online!

Each character has a 20% chance of beeing dropped.

Different approach, same length:

from random import*
print''.join(c[random()<.2:]for c in input())

Try it online!

movatica

Posted 2019-08-11T11:03:02.137

Reputation: 635

63 bytes in python 2 with a function – attinat – 2019-08-11T20:47:02.080

The rules explicitly state to write a full program: Create a cat program, a.k.a a program that takes an input and prints it. – movatica – 2019-08-11T20:51:44.687

This only reads the first line of input. – AKX – 2019-08-12T06:38:57.140

Problem does not state it had to read multiple lines. – movatica – 2019-08-12T18:43:39.073

8

Charcoal, 4 bytes

ΦS‽⁵

Try it online! Link is to verbose version of code. Explanation:

 S      Input a string
Φ       Filter where nonzero
  ‽⁵    Random number 0..4
        Implicitly print

You can use any number from 4 to 10 to get chances of 25% to 10% respectively.

Neil

Posted 2019-08-11T11:03:02.137

Reputation: 95 035

7

Befunge-98 (PyFunge), 11 bytes

>#@~3j4???,

Try it online!

Each character has a 25% chance of being removed. This decision is made at the three ? instructions.

? sets the program counter to one of the four directions, with equal probability. In this case, up & down wrap back around to the same instruction, so we can ignore those as options.

There are two ways out of the forest of ?s: to the right (output) and to the left (no output). This situation is symmetric, so if starting from the middle ?, there is a \$p_2 = 1/2\$ chance of outputting. The chance of outputting if starting from the right ? is \$p_3 = 1/2 * 1 + 1/2 * p_2 = 3/4\$. Therefore, after reading a character, we jump to the rightmost ? to determine whether or not to output.

negative seven

Posted 2019-08-11T11:03:02.137

Reputation: 1 931

5

Octave, 23 bytes

Generates an array of the same size as the input (strings in Octave are character arrays), checks each of the random numbers whether it is greater than 0.2 and then uses logical indexing to extract the characters at the corresponding positions.

@(s)s(rand(size(s))>.2)

Try it online!

flawr

Posted 2019-08-11T11:03:02.137

Reputation: 40 560

5

Jelly, 9 5 bytes

5X’µƇ

Try it online!

A monad which takes a Jelly string as its argument and returns the processed Jelly string. When used as a full program implicitly prints the output. Each character has a 20% chance of being removed.

Explanation

   µƇ | Filter using the following as a monad for each character:
5X    | - Random number between 1 and 5
  ’   | - Decreased by 1

Nick Kennedy

Posted 2019-08-11T11:03:02.137

Reputation: 11 829

5

Japt, 3 bytes

Each character has a 1 in 5 chance of being removed. The 5 can be changed to anything between 4 & 9, inclusive, or A for 10 to change the odds.

Æ5ö

Try it

Æ5ö     :Implicit input of string
Æ       :Filter by
 5ö     :  Random integer in the range [0,5), with 0 being falsey

Shaggy

Posted 2019-08-11T11:03:02.137

Reputation: 24 623

5

Wolfram Language (Mathematica), 24 bytes

Select[RandomReal[]>.2&]

Try it online!

Takes a list of characters as input. Each character has a .2 chance to be removed.

attinat

Posted 2019-08-11T11:03:02.137

Reputation: 3 495

5

05AB1E, 5 4 bytes

ʒ₄Ω≠

-1 byte thanks to @Grimy.

Try it online or run the same program 10 times.

Each character has a 25% change of being dropped.

Explanation:

ʒ     # Filter the characters of the (implicit) input-string by:
 ₄    #  Push 1000
  Ω   #  Pop and push a random digit from it
   ≠  #  And check that it's NOT 1 (!=1)
      # (after which the result is output implicitly)

could also be _ (==0).

Kevin Cruijssen

Posted 2019-08-11T11:03:02.137

Reputation: 67 575

25L can be for -1 (changes the chance from 20% to 25%, which is still acceptable). – Grimmy – 2019-08-12T11:32:09.130

@Grimy Nice one, thanks! :) – Kevin Cruijssen – 2019-08-12T11:38:48.440

4

MATL, 9 bytes

t&n&r.2>)

Exaplanation:

t         implicitly take input and duplicate it
 &n       compute the size of the input and...
   &r     generate a random array of that size
     .2>  check which entries of that array are greater than 0.2
        ) and use the result using logical indices to extract certain characters of the input

Try it online!

flawr

Posted 2019-08-11T11:03:02.137

Reputation: 40 560

4

Pyth, 8 5 bytes

sfO4Q

Try it online!

sfO4Q   Implicit: Q=eval(input())
 f  Q   Filter characters of Q where the following is truthy:
  O4      Random number in the range [0-4)
          Any non-zero value is truthy, so this will drop characters 25% of the time
s       Concatenate into string, implicit print

Previous version, 8 bytes:

s*Vm!!O4

Try it online!

s*Vm!!O4QQ   Implicit: Q=eval(input())
             Trailing QQ inferred
   m    Q    Map each character in Q using:
      O4       Choose random integer in [0-4)
    !!         Logical NOT twice - maps 0 to 0, anything else to 1
             The result is a list of 0s and 1s, with 0 having 25% chance to appear
 *V      Q   Vectorised multiplication of the above with Q
s            Concatenate into string, implicit print

Sok

Posted 2019-08-11T11:03:02.137

Reputation: 5 592

Q will throw an error if the input is not python-esque. Errors for example from [1 or a/b. Q, w and z will only work for single-line input, so the best option would probably be j.z – ar4093 – 2019-08-14T11:14:42.107

4

Cubix, 20 bytes

u$w\A|UDw@?;...>o._U

Try it online!

Longer than I had hoped as I had a number of no-ops that I can't seem to get rid of. The chance to drop a character is 25%. I assume this is okay.

    u $
    w \
A | U D w @ ? ;
. . . > o . _ U
    . .
    . .

Watch it run

Brief explanation:

  • A|A this initialises the the stack, Input all, reflect back, Input all (just an EOI -1)
  • ;? pop to of stack, test for EOI (-1).
  • _?@ if negative, reflect back into test and end on halt
  • $D jump the \ into the random direction setter.
    • from the direction setter, 3 direction lead to the o for output then back into the loop, one misses the o in it's path and goes straight to the loop.

MickyT

Posted 2019-08-11T11:03:02.137

Reputation: 11 735

3

APL (dzaima/APL), 10 9 bytesSBCS

Anonymous tacit prefix function. Each character has exactly 20% chance of being removed.

⊢⌿⍨4≥∘?5¨

Try it online!

 zero for each character

? random integer range 1–5 for each character

4≥ Boolean mask for those integers that are less than or equal to 4

⊢⌿⍨ filter the argument using that mask

Adám

Posted 2019-08-11T11:03:02.137

Reputation: 37 779

3

Retina, 15 bytes

/./_?(`.







Try it online! Explanation:

/./_

Process each character individually.

?(`

Perform a substitution at random. The first substitution deletes the character, while the other three leave it unchanged, thus giving a 25% chance of deleting the character. This can be decreased as necessary by appending additional pairs of newlines.

Neil

Posted 2019-08-11T11:03:02.137

Reputation: 95 035

3

R, 32 23 bytes

function(x)x[rt(x,3)<1]

Try it online!

A function taking a character vector as input and returning a processed character vector. Each character has a 20% chance of being removed.

Thanks to @Roland and @Giueseppe for helping save 7 bytes, and @JDL for a further 2!

Nick Kennedy

Posted 2019-08-11T11:03:02.137

Reputation: 11 829

1function(x)x[!rbinom(x,1,0.2)] – Roland – 2019-08-12T11:02:48.183

along the same lines as @Roland, function(x)x[rf(x,1,1)>1]; df(1,1,1) is about 0.16 which does the trick. – Giuseppe – 2019-08-12T13:49:37.103

or rt(x,3)>1 (about 20% chance) – JDL – 2019-08-12T20:00:49.297

2@JDL it’s <1, but thanks! Another 2 saved. – Nick Kennedy – 2019-08-12T20:04:14.583

3

T-SQL 2012, 83 bytes

Looping through the input from right to left removing 0 or 1 character.

25% chance for each character getting removed.

DECLARE @i varchar(max)='The cat ate my homework'

DECLARE @ int=len(@i)WHILE @>0SELECT
@i=stuff(@i,@,str(rand()*2)/2,''),@-=1PRINT @i

Explanation:

rand()*2 returns a float, which can't be used in the stuff command.

The str converts this into a varchar after rounding to nearest whole number. The float is being converted to a varchar(which isn't allowed as third parameter in stuff either).

This varchar has a 25% chance of being '2', 50% chance of being '1', 25% chance of being '0'. Dividing by 2, there is a 25% chance of result being 1. This division converts the varchar to an integer.

Integer is the expected third parameter in stuff function.

Try it online

t-clausen.dk

Posted 2019-08-11T11:03:02.137

Reputation: 2 874

Very nice trick with STR, I will have to remember that. Not sure it is fair to piggyback off your (uncounted) DECLARE in your (counted) code; but changing that would only cost you 1 byte, since you can eliminate the extra SET with DECLARE @ INT=len(@i) – BradC – 2019-08-12T15:16:48.447

@BradC I agree, and I will try to remember not to piggyback in the future – t-clausen.dk – 2019-08-13T07:33:20.850

2

PHP, 43 42 bytes

for(;''<$l=$argn[$i++];rand()%5&&print$l);

Try it online!

Each character has 20% of chance to be removed.

Night2

Posted 2019-08-11T11:03:02.137

Reputation: 5 484

2

J, 10 bytes

#~5>6?@$~#

Try it online!

Similar to Adam's APL answer, though I actually wrote it before looking at his.

  • 6.. $~ # Take the length of input # and shape $~ the number 6 into a list that long.
  • ?@ Treat each six in that list as a die and roll ? it.
  • >5 Is the die less than 5 (possible values are 0..5)? Use that boolean result to create a bit mask.
  • #~ Filter the input with that mask.

Jonah

Posted 2019-08-11T11:03:02.137

Reputation: 8 729

2

C# (Visual C# Interactive Compiler), 71 bytes

var y=new Random();foreach(var k in ReadLine())if(y.Next(5)<4)Write(k);

Try it online!

Embodiment of Ignorance

Posted 2019-08-11T11:03:02.137

Reputation: 7 014

I think that < 1 is eating too much. Maybe <3 or < 4 matches the parameters of the problem. Anyway this does not change the length of the code. – Luca – 2019-08-12T12:00:46.817

I haven't programmed in C# in a while, but why is't new Random().Next(5) directly possible? – Kevin Cruijssen – 2019-08-12T12:27:58.097

1@KevinCruijssen Because then the same seed will be used for each number, so each number be the same. Just try it with new Random().Next(5), all you will get is the whole input or nothing. – Embodiment of Ignorance – 2019-08-12T13:14:11.863

@Luca You're right, changed – Embodiment of Ignorance – 2019-08-12T13:14:32.637

@EmbodimentofIgnorance Yea, I noticed the output, I just don't really get how var y=new Random() with y.Next uses different seeds. You're still creating the Random-instance just once, and use .Next multiple times on it.. As a Java developer, I would expect both to either use the same seed or not. In Java they don't: Try it online. Which is why I'm confused..

– Kevin Cruijssen – 2019-08-12T13:34:30.823

1@KevinCruijssen when using new Random(), the default seed value is Environment.TickCount, which increments every millisecond. If they're all created in the same millisecond tick, they will all have the same seed. The answer is only using a single instance of Random, and when it's called it updates the internal seed value - so each time Next() is called, it creates a different output value. .Net Core however uses a singleton RNG to generate the seed, so it doesn't have this problem – Zac Faragher – 2019-08-13T06:40:08.263

is it allowed to have a statement that gets executed outside your function – LiefdeWen – 2019-08-13T12:14:58.777

@LiefdeWen To be honest, I don't know, but I'm following the precedent set by these answers: https://codegolf.stackexchange.com/a/188896/84206, https://codegolf.stackexchange.com/a/185440/84206, https://codegolf.stackexchange.com/a/185737/84206. I remember more, but those are the ones that I have tracked down

– Embodiment of Ignorance – 2019-08-13T18:35:12.900

@EmbodimentofIgnorance Okay, works for me – LiefdeWen – 2019-08-14T05:43:39.970

42 bytes? – LiefdeWen – 2019-08-14T05:51:48.293

@LiefdeWen Because the seed is always the index, you will always get the same result on each call. – Embodiment of Ignorance – 2019-08-14T08:21:46.000

@Holger Next(5) generates either 0, 1, 2, 3, or 4. 4 is not less than 4, so it is 80% of success – Embodiment of Ignorance – 2019-08-14T09:21:42.597

@EmbodimentofIgnorance Ok, I was confused by never seeing a char removed. But then, that’s pure chance, because of the rather small sample input. – Holger – 2019-08-14T09:27:18.900

@EmbodimentofIgnorance Does it need to be different per run? As far as I understand it just needs to have a different random seed per character – LiefdeWen – 2019-08-14T12:21:54.050

Input is restricted to STDIN or closest equivalent. and Output must be through STDOUT or the closest equivalent. If your language does have STDOUT, do not output in any other way. I'm 99.99% sure C# has STDOUT. – Benjamin Urquhart – 2019-08-14T17:27:11.760

1@BenjaminUrquhart Fixed, but added 26 bytes. Also, one can argue doesn't say input has to be from STDIN, but restricted to STDIN or closest equivalent, and function arguments may be the closest equivalent, but I'm not going to do that – Embodiment of Ignorance – 2019-08-14T17:31:54.723

2

Perl 5 -p, 18 bytes

s/./.2<rand&&$&/ge

Try it online!

Each character has a 20% chance of being dropped.

Xcali

Posted 2019-08-11T11:03:02.137

Reputation: 7 671

2

Javascript,  46   44  51 bytes

i=>alert([...i].filter(c=>Math.random()>.2).join``)

+7 bytes because of the added STDOUT requirement

-2 bytes thank to Birjolaxew


original answer: 44 bytes without the STDOUT requirement

i=>[...i].filter(c=>Math.random()>.2).join``

jonatjano

Posted 2019-08-11T11:03:02.137

Reputation: 331

Since you don't use the name of the function, you're allowed to just provide the function itself. Removing f= gets you down to 44 bytes. You may also input/output as an array, which should save you quite a bit.

– Birjolaxew – 2019-08-12T08:44:59.207

@Birjolaxew I'm not sure but as I understand it the question disallow the use of char array if the language has string – jonatjano – 2019-08-12T09:39:28.420

Yes, Andrew edited the question with additional requirements after my comment. This is generally frowned upon because it invalidates answers that were previously valid (in this case it's even debatable whether your initial answer fits the "Output must be through STDOUT" requirement). – Birjolaxew – 2019-08-12T11:19:21.887

What does join\`` mean? Can't find it in the spec (cause I don't really know what it is) – nick zoum – 2019-08-14T07:39:39.130

1

@nickzoum in es6 it is equivalent to join("") mdn revelent page

– jonatjano – 2019-08-14T07:40:47.850

2

Scala, 51 46 30 bytes

s=>s.flatMap(x=>if(math.random>.2)Some(x)else None)

Try it online!

PS. Like in many other solutions, the probability of dropping char is 20%.

Update:

-5 bytes by using String instead of Option[String] in flatMap

s=>s.flatMap(x=>if(math.random>.2)x+""else "")

30 bytes by using filter

s=>s.filter(x=>math.random>.2)

Dr Y Wit

Posted 2019-08-11T11:03:02.137

Reputation: 511

1You can shave off 7 bytes by changing scala.math.random to math.random and 0.2 to .2. Nice trick using ^ like that. – Kjetil S. – 2019-08-13T20:57:51.463

@KjetilS, thank you. I also posted function literals instead of function definitions as a solution. It is acceptable according to this: https://codegolf.stackexchange.com/questions/3885/tips-for-golfing-in-scala

– Dr Y Wit – 2019-08-14T10:02:08.347

1

C (gcc), 50 bytes

This program has a 20% chance of dropping a letter. Unfortunately the random number generator isn't seeded so you get the same sequence on each run. Basically the only trick is inverting the input character to halt the loop on EOF.

main(c){for(;c=~getchar();rand()%5&&putchar(~c));}

Try it online!

C (gcc), 64 59 bytes

Thanks to ceilingcat for the -5 bytes.

If you want the RNG seeded on each run.

main(c){for(srand(&c);c=~getchar();rand()%5&&putchar(~c));}

Try it online!

ErikF

Posted 2019-08-11T11:03:02.137

Reputation: 2 149

You don't have to use main() for Code Golf submissions, you can also define an arbitrary function that does what is required. So you can write f(c){...}. – G. Sliepen – 2019-08-23T11:41:03.037

1

Zsh, 53 41 bytes

-12, thanks to GammaFunction

41 bytes: try it online!

Converts the input to an array of characters, then tries to print each element c, unless it's eaten by the ((RANDOM%4)) evaluating to false!

for c (${(s::)1})((RANDOM%4))&&echo $c\\c

53 bytes: try it online!

A more straightforward, but verbose, iteration over string-length.

for ((;i<$#1;i++)){((RANDOM%4>0))&&echo "${1[i]}\c";}

roblogic

Posted 2019-08-11T11:03:02.137

Reputation: 554

1

Smart use of \c, I would not have remembered that! There's still a few optimizations to be made...

– GammaFunction – 2019-08-13T03:07:56.147

Nice, clever use of RANDOM and array conversion – roblogic – 2019-08-13T04:14:04.210

1

Lua, 69 68 bytes

for c in io.lines(nil,1)do io.write(math.random()>.2 and c or '')end

Try it online!

Kinda straightforward, but seems to be shortest version: iterate over stdin char by char (with io.lines… that name is misleading), then based on random value either print one or empty string (e.g. nothing).

val says Reinstate Monica

Posted 2019-08-11T11:03:02.137

Reputation: 409

1

Java

Non-terminating: 82 bytes

v->{for(int i;;i=System.in.read(),System.out.print(Math.random()<.2?"":(char)i));}

Terminating (TIO): 105 bytes

v->{var n=System.in;for(int i;n.available()>0;i=n.read(),System.out.print(Math.random()<.2?"":(char)i));}

Benjamin Urquhart

Posted 2019-08-11T11:03:02.137

Reputation: 1 262

Is dealing with stdout really necessary? Other answers only create a function just converting a string. Seems unfair towards Java. If this C# solution is valid, then s->s.filter(c->Math.random()<.2) is too.

– Holger – 2019-08-14T09:23:26.540

@Holger Input is restricted to STDIN or closest equivalent. and Output must be through STDOUT or the closest equivalent. If your language does have STDOUT, do not output in any other way. So no, that answer is not valid – Benjamin Urquhart – 2019-08-14T17:25:50.800

1

Zsh, 50 bytes

for c (${(s::)"$(<&0)"})
((RANDOM%5))&&echo -nE $c

Try it online!

Similar to RobLogic's answer, but following the input requirements more closely, and works for inputs with backslashes.

"$(<&0)" instead of "<&0" or $(<&0) because the first doesn't work in substitutions, and the second eats newlines. The -nE flags are necessary to prevent backslashes from being parsed as escape sequences, and to prevent newlines being inserted.

echo -nE

GammaFunction

Posted 2019-08-11T11:03:02.137

Reputation: 2 838

1

MathGolf, 5 bytes

æƒ√∞*

Try it online!

Explanation

æ       foreach character...
 ƒ      random float in range [0,1)
  √     take square root (making P(x < 0.5) = 0.25)
   ∞    pop a, push 2*a
    *   repeat character int(x) times

Each character will be repeated 0 or 1 times, depending on the random value. Since the expected value after the square root is shifted, there is a 25% probability that each character is removed.

Alternative 5-byter

gÉ;4w

Filter the characters by a random number in [0, 4]. Due to how filtering works, I have to discard the actual character within the filter loop, which adds 1 byte.

maxb

Posted 2019-08-11T11:03:02.137

Reputation: 5 754

0

GFortran, 120 bytes

Not too bad, if we use the deprecated RAN() function, which is pseudo-random, i.e. you get the same sequence each time. The proper way to generate random numbers in GFortran is with CALL RANDOM_SEED() and CALL RANDOM_NUMBER(R) but that's a lot of bytes!

character(99)S;read(*,'(A)')S;do i=1,len_trim(S)
if(ran(0)*5.gt.1)then;write(*,'(A)',advance="no")S(i:i)
endif;enddo;end

Try it online!

roblogic

Posted 2019-08-11T11:03:02.137

Reputation: 554

1Pseudo randomness is allowed, if that is the closest way you have to making random actions take hold. – Andrew – 2019-08-12T11:43:00.077

0

Oracle SQL, 133 bytes

select listagg(decode(sign(dbms_random.value-0.2),1,substr(x,level,1)))within group(order by level)from t connect by level<=length(x)

It works with an assumption that input data is stored in a table t(x), e.g.

with t(x) as (select 'The cat ate my homework' from dual)

Dr Y Wit

Posted 2019-08-11T11:03:02.137

Reputation: 511

0

Gaia, 10 bytes

⟨w8&Ø+ṛ⟩¦$

Try it online!

Has a 1/9th (11%) chance of removing any given character. This abuses the fact that the meta ¦ treats a string as a list, much as Python does.

 ⟨	⟩¦	| for each character do:
  w8&		| wrap as list and duplicate 8 times
     Ø+		| add empty string to that list
       ṛ	| select element at random
	  $	| and join with no separator
		| implicitly print top of stack

Giuseppe

Posted 2019-08-11T11:03:02.137

Reputation: 21 077

0

Python3, 61 bytes

Does this count? I guess if you consider execution across seconds of time "random"

import time
for c in input():print(end=c[time.time()%5<1:])

personjerry

Posted 2019-08-11T11:03:02.137

Reputation: 101

Welcome to the site! Is it possible you could add a link to an online testing site, such as TryItOnline!, so that other users can verify your answer? Especially given that, as far as I can see, this doesn't remove any characters when run.

– caird coinheringaahing – 2019-08-14T09:26:34.510

0

Pepe, 61 bytes

REEerEERREeeeeEeEeREEeEerEEEEErrEEReReEeRRERRErEereereReReree

Try it online!

There is 11.11% or \$\frac{1}9\$ chance of characters being deleted.

Explanation:

... # some-command -> (stack) // some-explanation

REEe # Input (str) -> (R)
rEE # Create label 0 -> (r) // main loop begins
  RREeeeeEeEe # Push 10 -> (R) // this is for the randomiser
              # R flag: place it in the beginning
  REEeEe # Random number from 1 to 10 -> (R)
  rEEEEE # Increment -> (r) // 0 > 1, for the next command
  rrEE # Create label 1 -> (r) // without previous command, the existing label 0 is replaced
       # r flag: Skip until rEe (return)
    Re # Pop -> (R) // removes the random number
    ReEe # Output as char & pop it -> (R)
    RRERRE # Push 0 2 times -> (R) // these are popped to fix the pos of R stack
  rEe # Return to where goto was called
  ree # Goto 1 if 1 != random from 1 to 10 // The whole rrEE ... rEe ree is an if..then
  re # Pop -> (r)
  ReRe # Pop 2 times -> (R)
ree # Loop while char of (R) != 0

u_ndefined

Posted 2019-08-11T11:03:02.137

Reputation: 1 253

0

Ruby -p, 27 bytes

The -p flag takes each line of input as the global variable $_ and runs it through the code block and then prints its contents. gsub modifies $_ by replacing characters that match the given regex (only works if -p or -n is present).

gsub(/.|\n/){$&if rand>0.2}

Try it online!

Value Ink

Posted 2019-08-11T11:03:02.137

Reputation: 10 608