Skip to content

Instantly share code, notes, and snippets.

@EvanHahn
Created April 15, 2014 02:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EvanHahn/10696763 to your computer and use it in GitHub Desktop.
Save EvanHahn/10696763 to your computer and use it in GitHub Desktop.
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