Commit d1d5c13d authored by Taddeüs Kroes's avatar Taddeüs Kroes

Added Python script to generate naive text programs

parent 8117b3b4
#!/usr/bin/env python
import sys
if __name__ == '__main__':
if len(sys.argv) < 2:
print >>sys.stderr, 'usage: python %s STRING' % sys.argv[0]
sys.exit(1)
def cmd(c):
return ('+' * c if c > 0 else '-' * -c) + '.'
input_string = ' '.join(sys.argv[1:]) + '\n'
ords = [0] + map(ord, input_string)
diffs = [ords[i + 1] - c for i, c in enumerate(ords[:-1])]
print '\n'.join(map(cmd, diffs))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment