Skip to main content
3 of 3
deleted 83 characters in body
Aaron
  • 3.8k
  • 1
  • 16
  • 30

<>, 27 + 3 for -v = 30 bytes =============

Here is a not-uniform-at-all solution where I mod N the sum of 15876 random picks of 0 or 1 :

0"~":*>:?vr%0=n;
1-$1+$^-1x

N must be input on the stack with -v flag, output is 0 for falsey and 1 for truthy.

A much smarter and uniform solution that work for 1/2^N instead :

4{:?!v1-}:">"$2p:"x"$3p:"^"$4p1+:">"$3p1+!
   ^1<
0n;
1n;>
 

For an input 3 you've got 1/8 chances of getting 1 and 7/8 of getting 0.

Explanation :

I append as much x as needed on the 4th line and surround them with directions so there is only two ways out of the x: either the falsey output or the next x. If all x go in the right direction, the last one will route to the truthy output.

For example for N=5, the final codespace is the following :

4{:?!v1-}:">"$2p:"x"$3p:"^"$4p1+:">"$3p1+!
   ^1<
0n; > > > > >
1n;>x>x>x>x>x>
    ^ ^ ^ ^ ^
Aaron
  • 3.8k
  • 1
  • 16
  • 30