Skip to content

Instantly share code, notes, and snippets.

@TheLie0
Last active July 3, 2018 13:52
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 TheLie0/a9f39c74d937c4ce8ecc8bca41ab8b60 to your computer and use it in GitHub Desktop.
Save TheLie0/a9f39c74d937c4ce8ecc8bca41ab8b60 to your computer and use it in GitHub Desktop.
Brainfuck program that returns the ascii values of the input characters
>>>,
[<<+>>>>>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++>++++++++++++++++++++++++++++++++++++++++++++++++<<<<< initialize memory
> read input
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++< set up memory for 100s
[+>+<[->-[>]<<]<[ if a is greater or equal to b then
- >>>>>+ add one at 100s place
<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<< put b back to 100
]<[ else
- >> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > [-<->] <<<+<reset a to value before checking
] +>> put back one so another loop can happen
]checks for 100s
<<->> reset number to the left to avoid later errors
>>++++++++++< set up memory for 10s
[+>+<[->-[>]<<]<[ if a is greater or equal to b then
- >>>>>>+ add one at 10s place
<<<++++++++++<< put b back to 10
]<[ else
- >> ++++++++++ > [-<->] <<<+<reset a to value before checking
] +>> put back one so another loop can happen
]checks for 10s
<<->> reset number to the left to avoid later errors
>>+< set up memory for 10s
[+>+<[->-[>]<<]<[ if a is greater or equal to b then
- >>>>>>>+ add one at 1s place
<<<<+<< put b back to 1
]<[ else
- >> + > [-<->] <<<+<reset a to value before checking
] +>> put back one so another loop can happen
]checks for 1s
<<->>>->> cleaning up the now usuless numbers
.[-]>.[-]>.[-] printing the answer
<<<<< go back to a spot for eventual new letters
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ out the value of ; into memory for splitting numbers
.----------------------------------------------------------- print and remove value
,]read next letter and check if there is one
<<< go back to memory location 0
@TheLie0
Copy link
Author

TheLie0 commented Jul 3, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment