Skip to content

Instantly share code, notes, and snippets.

@maxcountryman
Created December 16, 2010 00:32
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 maxcountryman/742840 to your computer and use it in GitHub Desktop.
Save maxcountryman/742840 to your computer and use it in GitHub Desktop.
Converts a string to Brainfuck
def string_process(s):
cs = map(ord, '{0}'.format(s))
clist = ''.join(['>' + c for c in
['+' * n for n in
[(i-i%10)/10 for i in cs]]])
cell_zero = ''.join(['<' * n for n in [len(cs)]]) + '-'
dlist = ''.join(['>' + c + '.' for c in
['+' * n for n in
[c-j for c,j in zip(cs, [(i-i%10) for i in cs])]]])
counter_table = '++++++++++[{0}{1}]{2}'.format(clist, cell_zero, dlist)
return counter_table
if __name__ == '__main__':
print ''.join(string_process('Problem?'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment