Alright, detective, one of our colleagues successfully observed our target person, Robby the robber. We followed him to a secret warehouse, where we assume to find all the stolen stuff. The door to this warehouse is secured by an electronic combination lock. Unfortunately our spy isn't sure about the PIN he saw, when Robby entered it.

The keypad has the following layout:
```
┌───┬───┬───┐
│ 1 │ 2 │ 3 │
├───┼───┼───┤
│ 4 │ 5 │ 6 │
├───┼───┼───┤
│ 7 │ 8 │ 9 │
└───┼───┼───┘
    │ 0 │
    └───┘
```
He noted the PIN `1357`, but he also said, it is possible that each of the digits he saw could actually be another adjacent digit (horizontally or vertically, but not diagonally). E.g. instead of the `1` it could also be the `2` or `4`. And instead of the `5` it could also be the `2`, `4`, `6` or `8`.

He also mentioned, he knows this kind of locks. You can enter an unlimited amount of wrong PINs, they never finally lock the system or sound the alarm. That's why we can try out all possible (*) variations.

\* possible in sense of: the observed PIN itself and all variations considering the adjacent digits

Can you help us to find all those variations? It would be nice to have a function, that returns an array (or a list in Java and C#)  of all variations for an observed PIN with a length of 1 to 8 digits. We could name the function `getPINs` (`get_pins` in python, `GetPINs` in C#). But please note that all PINs, the observed one and also the results, must be strings, because of potentially leading '0's. We already prepared some test cases for you.

Detective, we are counting on you!

For C# user: Do not use Mono. Mono is too slower when run your code.

Difficulty: interview

Starter code:

def get_pins(observed):
	

Solutions:
from itertools import product

ADJACENTS = ('08', '124', '2135', '326', '4157', '52468', '6359', '748', '85790', '968')

def get_pins(observed):
    return [''.join(p) for p in product(*(ADJACENTS[int(d)] for d in observed))]

def get_pins(observed):
  map = [['8','0'], ['1','2','4'], ['1','2','3','5'], ['2','3','6'], ['1','4','5','7'], ['2','4','5','6','8'],
         ['3','5','6','9'], ['4','7','8'], ['5','7','8','9','0'], ['6','8','9']]
  return map[int(observed[0])] if len(observed) == 1 else [x + y for x in map[int(observed[0])] for y in get_pins(observed[1:])]

adjacents = {
  '1': ['2', '4'],
  '2': ['1', '5', '3'],
  '3': ['2', '6'],
  '4': ['1', '5', '7'],
  '5': ['2', '4', '6', '8'],
  '6': ['3', '5', '9'],
  '7': ['4', '8'],
  '8': ['5', '7', '9', '0'],
  '9': ['6', '8'],
  '0': ['8'],
}

def get_pins(observed):
  if len(observed) == 1:
    return adjacents[observed] + [observed]
  return [a + b for a in adjacents[observed[0]] + [observed[0]] for b in get_pins(observed[1:])]

from itertools import product


PIN = {'1': ('1', '2', '4'), 
       '2': ('1', '2', '3', '5'), 
       '3': ('2', '3', '6'), 
       '4': ('1', '4', '5', '7'), 
       '5': ('2', '4', '5', '6', '8'), 
       '6': ('5', '6', '9', '3'), 
       '7': ('4', '7', '8'), 
       '8': ('7', '5', '8', '9', '0'), 
       '9': ('6', '8', '9'), '0': ('0', '8')}


def get_pins(observed):
    return [''.join(a) for a in product(*(PIN[b] for b in observed))]

from itertools import product

# Map a keypad number to the nearby numbers (including the number itself).
keypad_neighbors = {
    '1': ['1', '2', '4'],
    '2': ['1', '2', '3', '5'],
    '3': ['2', '3', '6'],
    '4': ['1', '4', '5', '7'],
    '5': ['2', '4', '5', '6', '8'],
    '6': ['3', '5', '6', '9'],
    '7': ['4', '7', '8'],
    '8': ['0', '5', '7', '8', '9'],
    '9': ['6', '8', '9'],
    '0': ['0', '8']
}

def get_pins(observed):
    # Build a 2D array of possibilities
    # Each row in the array is an entry
    # Each column is a possible number.
    pins = []
    for num in observed:
        pins.append(keypad_neighbors[num])
    
    # Generate every permutation of the possible numbers.
    for tup in product(*pins):
        yield ''.join(tup)

from itertools import product

PINS = {'1': '124', '2': '1253', '3': '236', '4': '1457', '5': '24568',
        '6': '3569', '7': '478', '8': '57890', '9': '689', '0': '08'}


def get_pins(observed):
    return list(map(''.join, product(*[PINS[num] for num in observed])))


def combos(ls):
    if len(ls) == 1:
        return ls[0]
    else:
        ans = []
        for s1 in combos(ls[1:]):
            for s2 in ls[0]:
                ans.append(s2+s1)
        return ans

def get_pins(observed):
    could_be = {
        '1': ['1', '2', '4'],
        '2': ['1', '2', '3', '5'],
        '3': ['2', '3', '6'],
        '4': ['1', '4', '5', '7'],
        '5': ['2', '4', '5', '6', '8'],
        '6': ['3', '5', '6', '9'],
        '7': ['4', '7', '8'],
        '8': ['5', '7', '8', '9', '0'],
        '9': ['6', '8', '9'],
        '0': ['8', '0']
    }
    return combos([could_be[c] for c in observed])

def get_pins(observed):

    numbers = {
        '1': [1,4,2],
        '2': [1,2,3,5],
        '3': [2,3,6],
        '4': [1,4,5,7],
        '5': [2,4,5,6,8],
        '6': [3,5,6,9],
        '7': [4,7,8],
        '8': [0,5,7,8,9],
        '9': [6,8,9],
        '0': [0,8]
    }
    
    from itertools import product
    possible = [numbers[o] for o in observed]
    return [''.join(map(str, p)) for p in product(*possible)]

from itertools import product


ADJACENT = {'1': '124', '2': '1235', '3': '236', '4': '1475', '5': '24568',
            '6': '3569', '7': '478', '8': '05789', '9': '689', '0': '08'}


def get_pins(observed):
    return [''.join(a) for a in product(*(ADJACENT[b] for b in observed))]


from itertools import product
get_pins = lambda o: map(lambda x: ''.join(x), product(*
 ['08 124 1235 236 1457 24568 3569 478 05789 689'.split(' ')
 [int(e)] for e in o]))