# Strobogrammatic number

For the given length n, find all n-length Strobogrammatic numbers.

**Strobogrammatic Number** is a number whose numeral is rotationally symmetric so that it appears the same when rotated 180 degrees. In other words, Strobogrammatic Number appears the same right-side up and upside down.

0 after 180° rotation : (0 → 0)

1 after 180° rotation : (1 → 1)

8 after 180° rotation : (8 → 8)

6 after 180° rotation : (6 →9)

9 after 180° rotation : (9 →6)

**Examples : **

Input : n = 2 Output : 88 11 96 69 Input : n = 4 Output : 8008 1001 9006 6009 8888 1881 9886 6889 8118 1111 9116 6119 8968 1961 9966 6969 8698 1691 9696 6699

Below is the Python3 implementation :

`# Python program to print all ` `# Strobogrammatic number of length n ` ` ` `# strobogrammatic function ` `def` `strobogrammatic_num(n): ` ` ` ` ` `result ` `=` `numdef(n, n) ` ` ` `return` `result ` ` ` `# definition function ` `def` `numdef(n, length): ` ` ` ` ` `if` `n ` `=` `=` `0` `: ` `return` `[""] ` ` ` `if` `n ` `=` `=` `1` `: ` `return` `[` `"1"` `, ` `"0"` `, ` `"8"` `] ` ` ` ` ` `middles ` `=` `numdef(n ` `-` `2` `, length) ` ` ` `result ` `=` `[] ` ` ` ` ` `for` `middle ` `in` `middles: ` ` ` `if` `n !` `=` `length: ` ` ` `result.append(` `"0"` `+` `middle ` `+` `"0"` `) ` ` ` ` ` `result.append(` `"8"` `+` `middle ` `+` `"8"` `) ` ` ` `result.append(` `"1"` `+` `middle ` `+` `"1"` `) ` ` ` `result.append(` `"9"` `+` `middle ` `+` `"6"` `) ` ` ` `result.append(` `"6"` `+` `middle ` `+` `"9"` `) ` ` ` `return` `result ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `'__main__'` `: ` ` ` ` ` `# Print all Strobogrammatic ` ` ` `# number for n = 3 ` ` ` `print` `(strobogrammatic_num(` `3` `)) ` |

*chevron_right*

*filter_none*

**Output :**

['818', '111', '916', '619', '808', '101', '906', '609', '888', '181', '986', '689']

**Reference :** https://en.wikipedia.org/wiki/Strobogrammatic_number

## Recommended Posts:

- Count number of triplets with product equal to given number with duplicates allowed
- Count number of trailing zeros in Binary representation of a number using Bitset
- Find minimum number to be divided to make a number a perfect square
- Maximum number formed from array with K number of adjacent swaps allowed
- Given number of matches played, find number of teams in tournament
- Number of ways to split a binary number such that every part is divisible by 2
- Number of times the largest perfect square number can be subtracted from N
- Number of possible permutations when absolute difference between number of elements to the right and left are given
- Find the number of positive integers less than or equal to N that have an odd number of digits
- Count number of digits after decimal on dividing a number
- Super Ugly Number (Number whose prime factors are in given set)
- Queries on sum of odd number digit sums of all the factors of a number
- Minimum number of given powers of 2 required to represent a number
- Build Lowest Number by Removing n digits from a given number
- Querying maximum number of divisors that a number in a given range has

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.