Problem 4¶
Recognize numbers shown on a digital LED display.
The number is encoded as follows:
a
___
f | |
| g | b
---
| | c
e |___|
d
For example, the number 2 is encoded as abged
.
Data:
Specify the valid identifiers for the segments. |
|
Define the mapping: segments identifier 🠒 displayed number. |
|
Define the inverse mapping of |
Functions:
|
Decode the given |
|
Encode the given |
- VALID_LETTERS = {'a', 'b', 'c', 'd', 'e', 'f', 'g'}¶
Specify the valid identifiers for the segments.
- TO_NUMBER = {'abc': 7, 'abcdef': 0, 'abcdefg': 8, 'abcdfg': 9, 'abcdg': 3, 'abdeg': 2, 'acdefg': 6, 'acdfg': 5, 'bc': 1, 'bcfg': 4}¶
Define the mapping: segments identifier 🠒 displayed number.
- FROM_NUMBER = {0: 'abcdef', 1: 'bc', 2: 'abdeg', 3: 'abcdg', 4: 'bcfg', 5: 'acdfg', 6: 'acdefg', 7: 'abc', 8: 'abcdefg', 9: 'abcdfg'}¶
Define the inverse mapping of
TO_NUMBER
: number 🠒 segments identifier