Does a Seven-Segment LED Digit Display Read the Same Rotated 180 Degrees?
WaymoSoftware Engineer · OnsiteLast updated
Decide whether a row of digits on a seven-segment LED display reads the same after the whole display is rotated by 180 degrees. Tests modeling each digit as lit segments, mapping segments under rotation, and comparing the reversed display.
An LED display shows a row of digits from 0 to 9, one digit per seven-segment cell. Write a function that decides whether the display reads exactly the same after the whole display is rotated by 180 degrees.
Function Signature
def looks_same_after_rotation(digits: list[int]) -> bool:
Rules
- Each cell has seven segments:
a(top),b(upper right),c(lower right),d(bottom),e(lower left),f(upper left) andg(middle). - The digits light these segments:
| Digit | Lit segments |
|---|---|
| 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 |
- Rotating the display by 180 degrees reverses the left-to-right order of the cells, and inside every cell it moves segment
atod,dtoa,btoe,etob,ctof,ftoc, and leavesgin place. - Return
Trueif and only if, after the rotation, every cell shows exactly the same set of lit segments as the cell in that position showed before. A rotated cell whose segment pattern is not one of the ten digits above can never match.
Constraints
1 <= len(digits) <= 10^50 <= digits[i] <= 9
Examples
Example 1
- Input:
digits = [6, 0, 9] - Output:
True - Explanation: After rotation the cells appear in reverse order, and each rotated cell shows: 9 becomes 6, 0 stays 0, 6 becomes 9. The display reads 6, 0, 9 again.
Example 2
- Input:
digits = [8, 1, 8] - Output:
False - Explanation: The 1 lights segments
bandc; rotated, it lightseandf, which is a bar on the left side of the cell and not the pattern for 1.
Example 3
- Input:
digits = [2, 5] - Output:
False - Explanation: Each of 2 and 5 looks like itself after rotation, but the cell order is reversed, so the display reads 5, 2.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.