Confusing numbers
Your task
A confusing number is one that, when each digit is rotated 180 degrees, becomes a different valid number. Only digits 0,1,6,8,9 are rotatable (0 to 0, 1 to 1, 6 to 9, 8 to 8, 9 to 6); any number containing 2,3,4,5,7 is not rotatable at all. Rotating reverses the digit order. Given n, count how many integers in [1, n] are confusing numbers. 1 <= n <= 1000000000.
Examples
confusing_number_ii(n: int) -> intExample 1
Input
confusing_number_ii(20)Output
6