Skip to content

Instantly share code, notes, and snippets.

@Property404
Created March 18, 2016 03:15
Show Gist options
  • Save Property404/6b9abc1508ad92a9d1ed to your computer and use it in GitHub Desktop.
Save Property404/6b9abc1508ad92a9d1ed to your computer and use it in GitHub Desktop.
Bounded Flushing Input (Brainfuck)
[
# Bounded flushing input for string, (unoptimized for easy reading)
# Iterations are predetermined
# This example takes a max of four characters
# Precondition: Start at origin
# Array has empty cell before it
# Empty "array" series of cells
# Postcondition: End at origin
# All cells(except last) in "arrays" are filled with input from keyboard
# until <enter> or until array ends. In this example, the array is FIVE
# characters long(Last character ends with \0)
#
# Concept:
# >(&a)
#
# {,----------[++++++++++>}(^a-1)
#
# +[,----------] # Flush
#
# ](^a-1)
#
# <[<]<(&a-1)
]
# Go to address
>>>
# Read input
,
# If not \n
----------[++++++++++
# Read next character
>,
# Two more times
----------[++++++++++
>,
----------[++++++++++
>,
# flush input if last input was not \n
----------[++++++++++>+[,----------]]
# End "loops"
]]]
# Return to head of string
<[<]>
# Go to origin
<<<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment