Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Seven Segment by pavelchashkov
from functools import reduce
def seven_segment(lit_seg, broken_seg):
data_digit = {
1: ['b', 'c'],
2: ['a', 'b', 'd', 'e', 'g'],
3: ['a', 'b', 'c', 'd', 'g'],
4: ['b', 'c', 'f', 'g'],
5: ['a', 'c', 'd', 'f', 'g'],
6: ['a', 'c', 'd', 'e', 'f', 'g'],
7: ['a', 'b', 'c'],
8: ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
9: ['a', 'b', 'c', 'd', 'f', 'g'],
0: ['a', 'b', 'c', 'd', 'e', 'f'],
}
lit_first_seg = set([x.lower() for x in lit_seg if x.islower()])
broken_first_seg = set([x.lower() for x in broken_seg if x.islower()])
all_first_seg = lit_first_seg | broken_first_seg
lit_second_seg = set([x.lower() for x in lit_seg if x.isupper()])
broken_second_seg = set([x.lower() for x in broken_seg if x.isupper()])
all_second_seg = lit_second_seg | broken_second_seg
count_first_digit = reduce(
lambda a, x: a + 1 if set(x).issubset(all_first_seg) and lit_first_seg.issubset(x) else a, data_digit.values(),
0)
count_second_digit = reduce(
lambda a, x: a + 1 if set(x).issubset(all_second_seg) and lit_second_seg.issubset(x) else a, data_digit.values(),
0)
return count_first_digit * count_second_digit
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"?')
Dec. 9, 2018