Maybe machine

From Esolang
Jump to navigation Jump to search

a maybe machine is a program that does this:

  • it takes in user input
  • it generates a random number that is either 1 or 0
  • it compares the number and the input
  • if it's true it prints the input forever
  • else it prints the input once

Implementations

><>

i68*->x0v
$:n:v >1>
>:n<>@_=?!;

ActionLang

Untested. uses the unofficial "random" command

input,random,2,modulus,subtract
nop,5,nop,nop,up
nop,jump,nop,nop,nop
up,output,halt,nop,nop
up,output,5,1,jump

Lua

x=io.read()print(x)for i=2,1/(x-math.random(0,1))do print(x)end

node.js

a=+prompt()
n=Math.random()<.5?1:0
do{console.log(a)}while(a==n)console.log(a)

The Second Coming

from random import randint
open a = Int(input())
if a == random.randint(0, 1):
    while True:
        print(a)
    endwhile
else:
    print(a)
endif

Thue

I::=:::
?::=.
?::=!
0.::=~0
1.::=~1
0!::=00.!
1!::=11.!
::=
I?

See also