d14p1
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
7273a296be
commit
f77d93de7e
|
@ -34,6 +34,7 @@ public class DayTests
|
|||
[DataRow(typeof(Day11), "1613", "510")]
|
||||
[DataRow(typeof(Day12), "4549", "120535")]
|
||||
[DataRow(typeof(Day13), "837", Day13Actual)]
|
||||
[DataRow(typeof(Day14), "5656", "")]
|
||||
public void CheckAllDays(Type dayType, string part1, string part2)
|
||||
{
|
||||
var s = Stopwatch.StartNew();
|
||||
|
@ -77,6 +78,7 @@ public class DayTests
|
|||
[DataRow(typeof(Day11), "1656", "195")]
|
||||
[DataRow(typeof(Day12), "226", "3509")]
|
||||
[DataRow(typeof(Day13), "17", Day13Test)]
|
||||
[DataRow(typeof(Day14), "1588", "2188189693529")]
|
||||
public void CheckTestInputs(Type dayType, string part1, string part2)
|
||||
{
|
||||
Day.UseTestInput = true;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
namespace aoc2021;
|
||||
|
||||
/// <summary>
|
||||
/// Day 14: <see href="https://adventofcode.com/2021/day/14"/>
|
||||
/// </summary>
|
||||
public sealed class Day14 : Day
|
||||
{
|
||||
private readonly string _template;
|
||||
private readonly Dictionary<string, string> _substitutionPairs;
|
||||
|
||||
public Day14() : base(14, "Extended Polymerization")
|
||||
{
|
||||
_template = Input.First();
|
||||
_substitutionPairs = Input.Skip(2).Select(l => l.Split(" -> ")).ToDictionary(k => k[0], v => v[1]);
|
||||
}
|
||||
|
||||
private string DoStep(string input)
|
||||
{
|
||||
var result = new StringBuilder();
|
||||
|
||||
for (var i = 0; i < input.Length - 1; i++)
|
||||
{
|
||||
var k = input.Substring(i, 2);
|
||||
if (_substitutionPairs.ContainsKey(k))
|
||||
{
|
||||
result.Append(k[0]);
|
||||
result.Append(_substitutionPairs[k]);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.Append(k);
|
||||
}
|
||||
}
|
||||
|
||||
result.Append(input[^1]);
|
||||
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
public override object Part1()
|
||||
{
|
||||
var s = Enumerable.Range(0, 10).Aggregate(_template, (current, _) => DoStep(current));
|
||||
|
||||
var most = s.ToCharArray()
|
||||
.GroupBy(c => c)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.Select(g => g.Count())
|
||||
.ToList();
|
||||
|
||||
return most.First() - most.Last();
|
||||
}
|
||||
|
||||
public override object Part2()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
KHSSCSKKCPFKPPBBOKVF
|
||||
|
||||
OS -> N
|
||||
KO -> O
|
||||
SK -> B
|
||||
NV -> N
|
||||
SH -> V
|
||||
OB -> V
|
||||
HH -> F
|
||||
HP -> H
|
||||
BP -> O
|
||||
HS -> K
|
||||
SN -> B
|
||||
PS -> C
|
||||
BS -> K
|
||||
CF -> H
|
||||
SO -> C
|
||||
NO -> H
|
||||
PP -> H
|
||||
SS -> P
|
||||
KV -> B
|
||||
KN -> V
|
||||
CC -> S
|
||||
HK -> H
|
||||
FN -> C
|
||||
OO -> K
|
||||
CH -> H
|
||||
CP -> V
|
||||
HB -> N
|
||||
VC -> S
|
||||
SP -> F
|
||||
BO -> F
|
||||
SF -> H
|
||||
VO -> B
|
||||
FF -> P
|
||||
CN -> O
|
||||
NP -> H
|
||||
KK -> N
|
||||
OP -> S
|
||||
BH -> F
|
||||
CB -> V
|
||||
HC -> P
|
||||
KH -> V
|
||||
OV -> V
|
||||
NK -> S
|
||||
PN -> F
|
||||
VV -> N
|
||||
HO -> S
|
||||
KS -> C
|
||||
FP -> F
|
||||
FH -> F
|
||||
BB -> C
|
||||
FB -> V
|
||||
SB -> K
|
||||
KP -> B
|
||||
FS -> C
|
||||
KC -> P
|
||||
SC -> C
|
||||
VF -> F
|
||||
VN -> B
|
||||
CK -> C
|
||||
KF -> H
|
||||
NS -> C
|
||||
FV -> K
|
||||
HV -> B
|
||||
HF -> K
|
||||
ON -> S
|
||||
CV -> N
|
||||
BV -> F
|
||||
NB -> N
|
||||
NN -> F
|
||||
BF -> N
|
||||
VB -> V
|
||||
VS -> K
|
||||
BK -> V
|
||||
VP -> P
|
||||
PB -> F
|
||||
KB -> C
|
||||
VK -> O
|
||||
NF -> F
|
||||
FO -> F
|
||||
PH -> N
|
||||
VH -> B
|
||||
HN -> B
|
||||
FK -> K
|
||||
PO -> H
|
||||
CO -> B
|
||||
FC -> V
|
||||
OK -> F
|
||||
OF -> V
|
||||
PF -> F
|
||||
BC -> B
|
||||
BN -> O
|
||||
NC -> K
|
||||
SV -> H
|
||||
OH -> B
|
||||
PC -> O
|
||||
OC -> C
|
||||
CS -> P
|
||||
PV -> V
|
||||
NH -> C
|
||||
PK -> H
|
|
@ -0,0 +1,18 @@
|
|||
NNCB
|
||||
|
||||
CH -> B
|
||||
HH -> N
|
||||
CB -> H
|
||||
NH -> C
|
||||
HB -> C
|
||||
HC -> B
|
||||
HN -> C
|
||||
NN -> C
|
||||
BH -> H
|
||||
NC -> B
|
||||
NB -> B
|
||||
BN -> B
|
||||
BB -> N
|
||||
BC -> B
|
||||
CC -> N
|
||||
CN -> C
|
Loading…
Reference in New Issue