@geek: It's funny. I came up with an extremely similar approach before even seeing your own:
def f(l):
""" transforms [a, b, c, d, ..., z] -> [a, b-a, c-b, d-c, ..., z-y]
ex: [3, 12, 10, 20] -> [3, 9, -2, 10]
"""
a = 0
for i in l:
yield i - a
a = i
# if input is a list, the code is equivalent to the following one liner.
# return (a - b for a, b in zip(l, [0]+ l[:-1]))
for i in f(ord(x) for x in "lebgeeks"):
sign = "+" if i > 0 else "-"
print(abs(i)*sign)
Next steps:
- multi cells and how to decide which initial setup is optimal. (I'll start with the one given by the Wikipedia example: 70 100 30 10).
- Write large numbers as multiple of factors. For instance 25 should be +++++[>+++++<-] instead of 25 "+" signs.
Any tips?