We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Maybe machine
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?
Python
from random import randint
x = int(input())
if x == randint(0, 1):
while True:
print(x)
else:
print(x)
golfed version by User:Hashibami:
from random import*
print(x:=input())
i=choice('01')
while x==i:print(x)
Golfed version by User:Dragoneater67:
from random import* print(x:=input()) i=randint(0,1) while i:print(x)
Bash
read -p "" i
if [[ "$i" == $((RANDOM % 2)) ]]
then
while true
do
echo "$i"
done
else
echo "$i"
fi