Created
April 12, 2012 17:12
-
-
Save cammckinnon/2369233 to your computer and use it in GitHub Desktop.
FizzBuzz (brainfuck)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Write fizz to memory using cells 0 to 5 inclusive | |
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<< | |
Write buzz to memory using cells 6 to 11 inclusive | |
>>>>>> | |
[-]>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>[-]<<<<< | |
Cell 12 will be used for ANDing the results of the fizz and buzz tests | |
Put up counter in cell 14 and down counter in cell 13 | |
>>>>>> | |
> | |
[-]++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
>[-]+< | |
while counter GE 0 | |
[ | |
Reset cell 12 | |
<[-]> | |
Compute mod 3 | |
>>[-]>[-]<<[->+>+<<]>>[-<<+>>]<<>>[-]<>>[-]+++[<<>>>>>>>>>[-]>[-]>[-]>[-]><<<<<<<<<<<<<>>>>>>>>>[-]>[-]<<<<<<<<<<[->>>>>>>>>+>+<<<<<<<<<<]>>>>>>>>>>[-<<<<<<<<<<+>>>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<<>>>><<<<>>>>>[-]+>[-]<<[<<<<>>>>>[-]]>[>]<[<<<<<[-]+++++<<>+<>>>>>>>[-]]<[-]>[-]>[-]>[-]<<<<<<<<<>>>>>>>>>>[-]]>[>]<[<<<<<<<<<<>>[>>>>[-]>[-]>[-]>[-]><<<<<<<<>>>>[-]>[-]<<<<<[->>>>+>+<<<<<]>>>>>[-<<<<<+>>>>>]<<<<<>>>>-----<<<<>>>>>[-]+>[-]<<[<<<<+<<+>>>>>>>[-]]>[>]<[<<<<<[-]>>>>>[-]]<[-]>[-]>[-]>[-]<<<<<<<]<<>>>>>>>>>>[-]]<[-]>[-]>[-]>[-]<<<<<<<<<<<<>>]<< | |
Conditionally print buzz | |
>>[-]>[-]>[-]>[-]><<<<<<>>[-]>[-]<<<[->>+>+<<<]>>>[-<<<+>>>]<<<>><<>>>[-]+>[-]<<[<<<<<+>>>>>>[-]]>[>]<[<<<<<<<<<<<<>[.>]<[<]>>>>>>>>>>>>[-]]<[-]>[-]>[-]>[-]<<<<< | |
>[-]<[-]<< | |
If neither fizz nor buzz were printed cell 12 will be 2 | |
If this is the case print the current up counter | |
< | |
>>>>>>>>>>>>>>>>>>>>>>>>>[-]>[-]>[-]>[-]><<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>[-]>[-]<<<<<<<<<<<<<<<<<<<<<<<<<<[->>>>>>>>>>>>>>>>>>>>>>>>>+>+<<<<<<<<<<<<<<<<<<<<<<<<<<]>>>>>>>>>>>>>>>>>>>>>>>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>]<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>--<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>[-]+>[-]<<[<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>[-]]>[>]<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| |
> | |
Print a linebreak using cell 12 as a scratch cell | |
<[-]++++++++++.[-]> | |
- | |
Add 1 to up counter | |
>+< | |
end while | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment