1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-19 22:16:57 +02:00
CodeWars/4kyu/the_observed_pin/solution.cs

30 lines
764 B
C#
Raw Normal View History

using System.Collections.Generic;
using System.Linq;
public class Kata {
private static Dictionary<char, string> Possible = new Dictionary<char, string>() {
{ '1', "124"}, { '2', "1235" }, { '3', "236" },
{ '4', "1457"}, { '5', "24568" }, { '6', "3569" },
{ '7', "478"}, { '8', "57890" }, { '9', "689" },
{ '0', "80" }
};
public static List<string> GetPINs(string observed) {
var result = new HashSet<string>() {
""
};
foreach (char observedDigit in observed) {
var possibleDigits = Possible[observedDigit];
result = new HashSet<string>(
result
.Select(pin => possibleDigits.Select(d => pin + d))
.Aggregate((acc, e) => acc.Union(e))
);
}
return result.ToList();
}
}