Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Sets & Strings solution in Clear category for Seven Segment by m.kurapov
import itertools
segments = 'ABCDEFG'
nums={
'BC' :1,
'ABDEG' :2,
'ABCDG' :3,
'BCFG' :4,
'ACDFG' :5,
'ACDEFG' :6,
'ABC' :7,
'ABCDEFG':8,
'ABCDFG' :9,
'ABCDEF' :0
}
def digit_count(lit_seg, broken_seg, filter_seg):
cnt = 0
digit_working_seg = lit_seg & filter_seg - broken_seg
digit_broken_seg = broken_seg & filter_seg
for l in range(0, len(digit_broken_seg)+1):
for subset in itertools.combinations(digit_broken_seg, l):
if "".join(sorted(digit_working_seg | set(subset))).upper() in nums:
cnt += 1
return cnt
def seven_segment(lit_seg, broken_seg):
return digit_count(lit_seg, broken_seg, set(segments)) * digit_count(lit_seg, broken_seg, set(segments.lower()))
Feb. 20, 2020
Comments: