Skip to content

Instantly share code, notes, and snippets.

@ewiger
Created February 16, 2015 12:45
Show Gist options
  • Save ewiger/0022bbde2edc8bbc91e2 to your computer and use it in GitHub Desktop.
Save ewiger/0022bbde2edc8bbc91e2 to your computer and use it in GitHub Desktop.
brainfuck `hello world` echo'er
'''
brainfuck `hello world` echo'er
test in here http://copy.sh/brainfuck/
wbr, yy
'''
from brainfuck import evaluate
def pack(coordinates):
lines = list()
for value in coordinates:
#power = log(value) / log(2)
divisor = 10
factor = int(value / divisor)
reminder = int(value % divisor)
if factor >= 2:
line = '>%s[>%s<-]>%s.' % \
('+' * factor, '+' * divisor, '+' * reminder)
else:
line = '>' + '+' * value
lines.append(line)
return lines
def pack2(coordinates):
lines = ['>']
last = 0
for value in coordinates:
#print value
if value > last:
offset = value - last
op = '+'
else:
offset = last - value
op = '-'
#print '%s%d %d %d' % (op, offset, value, last)
last = value
divisor = 10
factor = int(offset / divisor)
reminder = int(offset % divisor)
if factor >= 2:
line = '<%s[>%s<-]>%s.' % \
('+' * factor, op * divisor, op * reminder)
else:
line = op * offset + '.'
lines.append(line)
return lines
def say(message):
return pack2(ord(char) for char in message)
if __name__ == '__main__':
code = say('HB, Chris!')
#print '\n'.join(code)
print ''.join(code)
print evaluate(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment