Created
October 16, 2022 03:30
-
-
Save JustinStitt/ab9df55cd0781f1ce837cbe1eb8cf9ca to your computer and use it in GitHub Desktop.
my take at an if-else in BrainF**k . Checks for input of '5'
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
// accept input | |
, // at cell 1 | |
// subtract ascii '5' (53) from input | |
>++++++++++[<----->-]<--- // at cell 1 | |
// if inp == '5' | |
>+ // set zero flag to 1 (cell 2) | |
>+< // set else flag to 1 | |
<[>-<[-]] // change zero flag if inp not '5' (at cell 1) | |
// runs if zero flag 1 | |
>[ | |
[-] // zero cell 2 out | |
<[-] // zero cell 1 out | |
// load ascii 'Y' (89) | |
>++++++++++ // load counter for 10 at cell 2 | |
[<+++++++++>-]<- // 10 * 9 = 90 minus 1 = 89 | |
>>-< // go unset else flag and return to cell 2 | |
] | |
> // go check else flag | |
[ | |
[-] // zero ourself out | |
// load ascii 'N' (78) 10 * 8 minus 2 | |
>++++++++++ // load counter with 10 | |
[<++++++++>-]<-- | |
. // print 'N' | |
> | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment