Created
July 31, 2014 05:06
-
-
Save iconjack/91afb4c2e975c031f0d9 to your computer and use it in GitHub Desktop.
Solutions to Ken's LED Puzzle
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
digits = [ | |
# B C D A B C A B C | |
# E F F F F | |
# G H H H H | |
# I L L J K J K | |
# M N N M N | |
# O P P O P | |
# R S T Q R S T Q R S | |
# | |
"BCEFGHILMNOPRS", "DFHLNPT", "ABCFHJKMOQRST", "ABCFHJKNPQRS", | |
# | |
# | |
# A A B C D B C A B C D | |
# E F E E F | |
# G H G G H | |
# I J K L I J K I J K L | |
# N N M N N | |
# P P O P P | |
# T Q R S R S T | |
"AEFHIJKLNPT", "ABCDEGIJKNPQRS", "BCEGIJKMNOPRS", "ABCDFHLNPT", | |
# | |
# B C B C B C A B C | |
# E F E F E F E F | |
# G H G H G H G H | |
# J K J K L I J K L I J K | |
# M N N M N M N | |
# O P P O P O P | |
# R S R S Q T Q R S | |
# | |
"BCEFGHJKMNOPRS", "BCEFGHJKLNPRS", "BCEFGHIJKLMNOPQT", "ABCEFGHIJKMNOPQRS", | |
# | |
# B C D A B C A B C D A B C D | |
# E E F E E | |
# G G H G G | |
# I I L I J K I J K | |
# M M N M M | |
# O O P O O | |
# R S T Q R S Q R S T Q | |
# | |
"BCDEGIMORST", "ABCEFGHILMNOPQRS", "ABCDEGIJKMOQRST", "ABCDEGIJKMOQ" ] | |
from itertools import combinations, product | |
for n in [6,5,4]: | |
count = 0 | |
for combo in combinations("ABCDEFGHIJKLMNOPQRST", n): | |
buckets = [None]*(2**n) | |
for digit in digits: | |
sig = reduce(lambda a, b: (a<<1) + int(b), [c in digit for c in combo]) | |
if buckets[sig] is not None: break | |
buckets[sig] = digit | |
else: # (didn't break) | |
print "".join(combo) | |
count += 1 | |
print "\n%4d solutions for n = %d\n" % (count,n) | |
print; print "~fini~" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment