Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System;
- public class Kata
- {
- public static List<string> GetPINs(string observed)
- {
- var result = new List<string>();
- var max = Convert.ToInt32(new String('9', observed.Length));
- var masks = Enumerable.Range(0, max + 1).Select(s => AddZeroes(s, observed.Length));
- foreach (string mask in masks)
- {
- try
- {
- var pin = "";
- for (int i = 0; i < observed.Length; i++)
- {
- pin += GetAdjacent(observed[i])[mask[i] - '0'];
- }
- result.Add(pin);
- }
- catch
- {
- continue;
- }
- }
- return result;
- }
- private static string AddZeroes(int n, int length)
- {
- string result = n.ToString();
- result = new String('0', length - result.Length) + result;
- return result;
- }
- private static List<char> GetAdjacent(char digit)
- {
- if (digit == '0') return new List<char>() {'0', '8'};
- if (digit == '1') return new List<char>() {'1', '2', '4'};
- if (digit == '2') return new List<char>() {'1', '2', '3', '5'};
- if (digit == '3') return new List<char>() {'2', '3', '6'};
- if (digit == '4') return new List<char>() {'1', '4', '5', '7'};
- if (digit == '5') return new List<char>() {'2', '4', '5', '6', '8'};
- if (digit == '6') return new List<char>() {'3', '5', '6', '9'};
- if (digit == '7') return new List<char>() {'4', '7', '8'};
- if (digit == '8') return new List<char>() {'5', '7', '8', '9', '0'};
- if (digit == '9') return new List<char>() {'6', '8', '9'};
- throw new ArgumentOutOfRangeException();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement