finish d8p2
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
1673962a72
commit
d38a4e70c8
|
@ -8,12 +8,11 @@ public sealed class Day08 : Day
|
|||
private static readonly List<char[]> PossibleMappings = "abcdefg".ToCharArray().Permute().Select(m => m.ToArray()).ToList();
|
||||
public Day08() : base(8, "Seven Segment Search")
|
||||
{
|
||||
UseTestInput = true;
|
||||
}
|
||||
|
||||
private static int MatchDigit(char[] lit)
|
||||
private static int MatchDigit(string lit)
|
||||
{
|
||||
return new string(lit) switch
|
||||
return lit switch
|
||||
{
|
||||
"1110111" => 0,
|
||||
"0010010" => 1,
|
||||
|
@ -33,31 +32,47 @@ public sealed class Day08 : Day
|
|||
{
|
||||
var s = line.Split(" | ").Select(s => s.Split(' ')).ToList();
|
||||
int i;
|
||||
char[] lit;
|
||||
for (i = 0; i < PossibleMappings.Count; i++)
|
||||
{
|
||||
var lit = "0000000".ToCharArray();
|
||||
var matches = new int[10];
|
||||
var matches = 0;
|
||||
var failed = false;
|
||||
foreach (var signal in s[0])
|
||||
{
|
||||
lit = "0000000".ToCharArray();
|
||||
foreach (var c in signal)
|
||||
lit[Array.IndexOf(PossibleMappings[i], c)] = '1';
|
||||
|
||||
var match = MatchDigit(lit);
|
||||
var match = MatchDigit(new(lit));
|
||||
if (match == -1)
|
||||
{
|
||||
failed = true;
|
||||
break;
|
||||
}
|
||||
matches[match] = 1;
|
||||
|
||||
matches++;
|
||||
}
|
||||
|
||||
if (failed) continue;
|
||||
if (matches.All(m => m == 1)) break;
|
||||
if (matches == 10) break;
|
||||
}
|
||||
|
||||
var mapping = PossibleMappings[i];
|
||||
return 1;
|
||||
if (i == PossibleMappings.Count)
|
||||
{
|
||||
throw new("no mapping found");
|
||||
}
|
||||
|
||||
var digits = new StringBuilder();
|
||||
foreach (var o in s[1])
|
||||
{
|
||||
lit = "0000000".ToCharArray();
|
||||
foreach (var c in o)
|
||||
lit[Array.IndexOf(PossibleMappings[i], c)] = '1';
|
||||
|
||||
digits.Append(MatchDigit(new(lit)));
|
||||
}
|
||||
|
||||
return int.Parse(digits.ToString());
|
||||
}
|
||||
|
||||
public override string Part1() =>
|
||||
|
|
Loading…
Reference in New Issue