A vintage pressure gauge displays its reading as a row of mechanical digit wheels mounted inside a round housing. If a technician accidentally mounts the housing upside down (rotated 180 degrees), the digits may reform into a completely different, still-legible number -- a misreading that could go unnoticed.
When the housing is flipped, each individual digit wheel rotates as follows: 0 stays 0, 1 stays 1, 6 becomes 9, 8 stays 8, and 9 becomes 6. The digits 2, 3, 4, 5, and 7 turn into shapes that are not valid digits at all, so a reading containing any of them can never produce a legible misreading. Flipping the whole housing 180 degrees also reverses the left-to-right order of the digit wheels, in addition to transforming each digit's shape -- so the misread number is formed by rotating every digit individually and then reading the wheels off in the reverse order from the original.
Given a gauge reading, determine whether it is a "confusing" reading: every one of its digits must rotate to a valid digit, and the resulting rotated-and-reversed number must be numerically different from the original reading.
A single line containing one integer n, the gauge reading.
Print true if the reading is confusing as defined above, or false otherwise.
1 <= n <= 10^9Example 1
Input
6
Expected
true
Explanation
The single digit 6 rotates to 9, a valid digit, and reversing a single digit changes nothing. The rotated reading is 9, which differs from the original 6, so the reading is confusing: true.
Example 2
Input
89
Expected
true
Explanation
Rotating each digit gives 8->8 and 9->6. Reversing the digit order after rotation means the digit that was originally last (9, rotated to 6) now comes first, and the digit that was originally first (8, rotated to 8) now comes last, giving the rotated reading 68. Since 68 differs from 89 and both digits are valid, the reading is confusing: true.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →