Skip to content

Instantly share code, notes, and snippets.

@EvanHahn

EvanHahn/158.bf

Created Apr 15, 2014
Embed
What would you like to do?
Daily programmer #158, in Brainfuck
first digit
,------------------------------------------------
[>++++++++++<-]
second digit
,------------------------------------------------
>>
third digit
,------------------------------------------------
[>++++++++++<-]
fourth digit
,------------------------------------------------
make the first number
<<
[>+<-]
make the second number
>>
[>+<-]
add the two numbers into cell 0
<
[<+>>+<-]
>>
[<<<+>+>>-]
make four copies of cell 0
<<<
[>>>+>+>+>+<<<<<<-]
square this number
>>>>>-
[
<[<+>-]
>-
>[<<+>>>+<-]
>[<+>-]
<<
]
make the expected number
<<<
[-<<
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>>]
<[-<+>]
subtract the actual from the expected
<[->>>-<<<]
is the expected nonzero?
>>>
[
print "n"
<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.
print "o"
+
.
make this print cell negative 1
[-]-
make it 0
>[-]
]
it was zero!
<+[
print "yes"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.
--------------------.
++++++++++++++.
[-]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment