Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First - With Number Visualization solution in Clear category for Seven Segment by Ed0s
from itertools import combinations
def findsubs(s):
final = []
for i in range(1, len(s) + 1):
for j in list(combinations(s, i)):
final.append(list(j))
return final
class Tablero:
def __init__(self, digits=None):
if digits is None:
self.digits = []
else:
self.digits = digits
def __repr__(self):
aux = []
for digit in self.digits:
rep = [[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "],
[" ", " ", " ", " ", " "]]
for lit in digit.lit:
if lit.lower() == "a":
rep[0][1], rep[0][2], rep[0][3] = "-", "-", "-"
elif lit.lower() == "b":
rep[1][4], rep[2][4], rep[3][4] = "|", "|", "|"
elif lit.lower() == "c":
rep[5][4], rep[6][4], rep[7][4] = "|", "|", "|"
elif lit.lower() == "d":
rep[8][1], rep[8][2], rep[8][3] = "-", "-", "-"
elif lit.lower() == "e":
rep[5][0], rep[6][0], rep[7][0] = "|", "|", "|"
elif lit.lower() == "f":
rep[1][0], rep[2][0], rep[3][0] = "|", "|", "|"
elif lit.lower() == "g":
rep[4][1], rep[4][2], rep[4][3] = "-", "-", "-"
final = []
for fila in rep:
final.append("".join(fila))
aux.append(final)
final = []
for i in range(9):
aux2 = ""
for j in range(len(aux)):
aux2 += aux[j][i] + " "
final.append(aux2)
return "\n".join(final)
class Marker:
def __init__(self, lit):
self.lit = lit
def isdigit(self):
if set([x.upper() for x in self.lit]) == {"A", "B", "C", "D", "E", "F"}:
return "0"
elif set([x.upper() for x in self.lit]) == {"B", "C"}:
return "1"
elif set([x.upper() for x in self.lit]) == {"A", "B", "D", "E", "G"}:
return "2"
elif set([x.upper() for x in self.lit]) == {"A", "B", "C", "D", "G"}:
return "3"
elif set([x.upper() for x in self.lit]) == {"B", "C", "F", "G"}:
return "4"
elif set([x.upper() for x in self.lit]) == {"A", "C", "D", "F", "G"}:
return "5"
elif set([x.upper() for x in self.lit]) == {"A", "C", "D", "E", "F", "G"}:
return "6"
elif set([x.upper() for x in self.lit]) == {"A", "B", "C"}:
return "7"
elif set([x.upper() for x in self.lit]) == {"A", "B", "C", "D", "E", "F", "G"}:
return "8"
elif set([x.upper() for x in self.lit]) == {"A", "B", "C", "D", "F", "G"}:
return "9"
else:
return False
def update_lit(self, new):
self.lit = new
def seven_segment(lit_seg, broken_seg):
numeros = []
lit_seg1 = [x for x in lit_seg if x.isupper()]
lit_seg2 = [x for x in lit_seg if x.islower()]
broken_seg1 = [y for y in broken_seg if y.isupper()]
broken_seg2 = [y for y in broken_seg if y.islower()]
d1 = Marker(lit_seg1)
d2 = Marker(lit_seg2)
def check_number(m1, m2):
if m1.isdigit() and m2.isdigit():
print(Tablero([m1, m2]))
numeros.append(int(m1.isdigit() + m2.isdigit()))
print(numeros)
# 1.- Check if only the lit segments are a valid number
check_number(d1, d2)
# 2.- Let the first digit static and the second one changing
for broken in findsubs(broken_seg2):
aux = d2.lit
d2.update_lit(d2.lit + broken)
check_number(d1, d2)
d2.update_lit(aux)
# 3.- Let the second digit static and the first one changing
for broken in findsubs(broken_seg1):
aux = d1.lit
d1.update_lit(d1.lit + broken)
check_number(d1, d2)
d1.update_lit(aux)
# 4.- Two digits changing
for broken1 in findsubs(broken_seg1):
aux1 = d1.lit
d1.update_lit(d1.lit + broken1)
for broken2 in findsubs(broken_seg2):
aux2 = d2.lit
d2.update_lit(d2.lit + broken2)
check_number(d1, d2)
d2.update_lit(aux2)
d1.update_lit(aux1)
return len(numeros)
if __name__ == '__main__':
assert seven_segment({'B', 'C', 'b', 'c'}, {'A'}) == 2, '11, 71'
assert seven_segment({'B', 'C', 'a', 'f', 'g', 'c', 'd'}, {'A', 'G', 'D', 'e'}) == 6, '15, 16, 35, 36, 75, 76'
assert seven_segment({'B', 'C', 'a', 'f', 'g', 'c', 'd'}, {'A', 'G', 'D', 'F', 'b', 'e'}) == 20, '15...98'
print('"Run" is good. How is "Check"?')
March 4, 2019