Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Short and clear solution in Clear category for Seven Segment by Merzix
def seven_segment(lit_seg, broken_seg):
digits = {
0: {'a', 'b', 'c', 'd', 'e', 'f'},
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'},
}
low = set()
high = set()
for i in lit_seg:
if i.islower():
low.add(i)
else:
high.add(i)
get_count = lambda digit, seg: (digit ^ seg) <= broken_seg
low_count = high_count = 0
for digit in digits.values():
low_count += get_count(digit, low)
high_count += get_count({x.upper() for x in digit}, high)
return low_count * high_count
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'
Sept. 12, 2018
Comments: