From 5102c48e6dd3b8552fef59c83c794fe8c54d68d8 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Sat, 10 Dec 2022 14:43:02 -0500 Subject: [PATCH] tidy up --- AOC2022/Day10.cs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/AOC2022/Day10.cs b/AOC2022/Day10.cs index 12d0349..1e9ae1f 100644 --- a/AOC2022/Day10.cs +++ b/AOC2022/Day10.cs @@ -15,19 +15,13 @@ public sealed class Day10 : Day public override void ProcessInput() { int x = 1, cycle = 1; - foreach (var line in Input) - { - if (line.StartsWith("addx")) - { - CpuTick(ref cycle, x); - CpuTick(ref cycle, x); - x += int.Parse(line.Split(' ')[1]); - } - else - { - CpuTick(ref cycle, x); - } + { + CpuTick(ref cycle, x); + if (!line.StartsWith("addx")) continue; + + CpuTick(ref cycle, x); + x += int.Parse(line.Split(' ')[1]); } } @@ -35,14 +29,11 @@ public sealed class Day10 : Day { if ((cycle - 20) % 40 == 0) _interestingSignals.Add(x * cycle); - if (new[] { x - 1, x, x + 1 }.Contains((cycle - 1) % 40)) _charMap[cycle] = '█'; - cycle++; } public override object Part1() => _interestingSignals.Sum(); - public override object Part2() => string.Join(Environment.NewLine, _charMap.Chunk(40).Select(s => new string(s))); } \ No newline at end of file