Created
April 28, 2020 12:32
-
-
Save BalintCsala/5d7028ee7fec5cc5d64d7151a4fd77e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| # Setup | |
| # Set first cell to 255 for easy return | |
| - | |
| # Read in program until exclamation mark | |
| # Each instruction consists of a marker and a char | |
| --------------------------------- | |
| [ | |
| +++++++++++++++++++++++++++++++++ | |
| >>, | |
| --------------------------------- | |
| ] | |
| +++++++++++++++++++++++++++++++++ | |
| # Create marker for data start and current data location | |
| >>>->>-<<< | |
| # Go back to first cell | |
| +[-<+]- | |
| # Mark first cell with execution marker | |
| >- | |
| # Put current cursor at the first instruction | |
| > | |
| # Execute code while current location isn't an exclamation mark | |
| --------------------------------- | |
| [ | |
| +++++++++++++++++++++++++++++++++ | |
| # Test instruction for "increment" | |
| ------------------------------------------- | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Go to data and increment | |
| >+ | |
| # Go back to start of data | |
| <<<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "input" | |
| - | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Go to data and read in data | |
| >, | |
| # Go back to start of data | |
| <<<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "decrement" | |
| - | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Go to data and decrement | |
| >- | |
| # Go back to start of data | |
| <<<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "output" | |
| - | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Go to data and print data | |
| >. | |
| # Go back to start of data | |
| <<<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "move left" | |
| -------------- | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Reset to 0 and set current marker before the last one | |
| +<<- | |
| # Go back to start of data | |
| <<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "move right" | |
| -- | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Find current data point | |
| >>+[->>+]- | |
| # Reset to 0 and set current marker before the last one | |
| +>>- | |
| # Go back to start of data | |
| <<+[-<<+]- | |
| # Go back to current instruction | |
| <<+[-<<+]-> | |
| # Go to temp0 | |
| > | |
| - | |
| ]< | |
| # Test instruction for "loop open" | |
| ----------------------------- | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| - | |
| ]< | |
| # Test instruction for "loop close" | |
| -- | |
| # If 0 | |
| [>+>>+<<<-]>[<+>-]+ | |
| >>[<<->>[-]] | |
| << | |
| [ | |
| # Find start of data | |
| +[->>+]- | |
| # Go back one cell, clear it and insert 1 | |
| <[-]+ | |
| # While not zero, | |
| - | |
| ]< | |
| # Reset instruction | |
| +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
| # Move instruction marker | |
| <+>>-> | |
| --------------------------------- | |
| # End of loop | |
| ] | |
| +++++++++++++++++++++++++++++++++ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment