Last active
May 10, 2017 18:10
-
-
Save jarhill0/5d6d2bc49e22bf77da0ba33171db47ed 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
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