1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-11-25 18:21:55 +01:00
CodeWars/4kyu/the_observed_pin/solution.cs
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

29 lines
764 B
C#

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();
}
}