Skip to content

Instantly share code, notes, and snippets.

@christianp
Created February 28, 2015 20:28
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 christianp/8cba524a4aa67133a89a to your computer and use it in GitHub Desktop.
Save christianp/8cba524a4aa67133a89a to your computer and use it in GitHub Desktop.
total segment toggles as a 7-segment display counts up from 1234 to 6789 - https://twitter.com/wacnt/status/566024138481881088
"""
Layout:
0
1 2
3
4 5
6
"""
from itertools import product
segments = ['1110111','0010010','1011101','1011011','0111010','1101011','0101111','1010010','1111111','1111010']
toggles = {}
for a,b in product(range(10),repeat=2):
t = 0
for da,db in zip(segments[a],segments[b]):
if da!=db:
t += 1
toggles[(str(a),str(b))] = t
total = 0
for old,new in zip(range(1234,6789),range(1235,6790)):
for dold,dnew in zip(str(old),str(new)):
total += toggles[(dold,dnew)]
print(total)
@christianp
Copy link
Author

20976

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment