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

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

Edit : I might be missing something, butHere is a not-uniform-at-all solution where I think it's just impossible ifmod N isn't a multiplethe sum of 2,3 or 4 (the number15876 random picks of exits from a0 or 1 x symbol). If someone knows the maths to make it work I'll:

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

N must be glad to implement itinput on the stack with !-v flag, output is 0 for falsey and 1 for truthy.

Let's hope you will still be interested by an answerA much smarter and uniform solution that work for 1/2^N instead :

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So forFor 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>
    ^ ^ ^ ^ ^

<>, Invalid =============

Edit : I might be missing something, but I think it's just impossible if N isn't a multiple of 2,3 or 4 (the number of exits from a x symbol). If someone knows the maths to make it work I'll be glad to implement it !

Let's hope you will still be interested by an answer for 1/2^N :

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So 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>
    ^ ^ ^ ^ ^

<>, 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>
    ^ ^ ^ ^ ^
added 168 characters in body
Source Link
Aaron
  • 3.8k
  • 1
  • 16
  • 30

<>, Invalid =============

I'll try thinking ofEdit : I might be missing something, but I think it's just impossible if N isn't a way to do 1/N probability in ><>multiple of 2, in3 or 4 (the number of exits from a x symbol). If someone knows the meantime I thoughtmaths to make it work I'll be glad to implement it !

Let's hope you might find awill still be interested by an answer for 1/2^N answer interesting.:

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So 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>
    ^ ^ ^ ^ ^

<>, Invalid =============

I'll try thinking of a way to do 1/N probability in ><>, in the meantime I thought you might find a 1/2^N answer interesting.

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So 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>
    ^ ^ ^ ^ ^

<>, Invalid =============

Edit : I might be missing something, but I think it's just impossible if N isn't a multiple of 2,3 or 4 (the number of exits from a x symbol). If someone knows the maths to make it work I'll be glad to implement it !

Let's hope you will still be interested by an answer for 1/2^N :

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So 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>
    ^ ^ ^ ^ ^
Source Link
Aaron
  • 3.8k
  • 1
  • 16
  • 30

<>, Invalid =============

I'll try thinking of a way to do 1/N probability in ><>, in the meantime I thought you might find a 1/2^N answer interesting.

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

Input is to be input directly on the stack with -v to avoid the tedious integer parsing. Truthey output will be 1, falsey will be 0. So 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>
    ^ ^ ^ ^ ^