Skip to content

Instantly share code, notes, and snippets.

@jarhill0
Last active May 10, 2017 18:10
Show Gist options
  • Save jarhill0/5d6d2bc49e22bf77da0ba33171db47ed to your computer and use it in GitHub Desktop.
Save jarhill0/5d6d2bc49e22bf77da0ba33171db47ed to your computer and use it in GitHub Desktop.
def main():
print("I'm gonna generate a brainfuck program to print your text. It will be horribly inefficient, but it's faster",
"than writing it yourself…")
my_string = input('Enter the output string: ')
print(encode_string_to_brainfuck(my_string))
def encode_string_to_brainfuck(my_string):
output = ''
last_val = 0
for char in my_string:
if ord(char) > last_val:
output += '+' * (ord(char) - last_val)
elif ord(char) < last_val:
output += '-' * (last_val - ord(char))
output += '.'
last_val = ord(char)
return output
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment