Created
February 28, 2015 20:28
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
20976