From a0e5125a23ae250197d15b048e2b028be1d97198 Mon Sep 17 00:00:00 2001 From: Parnic Date: Fri, 3 Dec 2021 10:09:11 -0600 Subject: [PATCH] Tweak output formatting --- src/02.cs | 59 +++++++++++++++++++++++++++---------------------------- src/03.cs | 5 ++++- 2 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/02.cs b/src/02.cs index 65ef9b4..52b9464 100644 --- a/src/02.cs +++ b/src/02.cs @@ -4,6 +4,8 @@ namespace aoc2021 { internal static void Go() { + Logger.Log("Day 2"); + Logger.Log("-----"); var lines = File.ReadAllLines("inputs/02.txt"); var instructions = new List(); foreach (var instruction in lines) @@ -18,6 +20,7 @@ namespace aoc2021 Part1(instructions); Part2(instructions); + Logger.Log(""); } struct Instruction @@ -34,25 +37,23 @@ namespace aoc2021 private static void Part1(IEnumerable instructions) { + using var t = new Timer(); Position pos = new(); - using (var t = new Timer()) + foreach (var instruction in instructions) { - foreach (var instruction in instructions) + switch (instruction.Direction) { - switch (instruction.Direction) - { - case "forward": - pos.h += instruction.Amount; - break; + case "forward": + pos.h += instruction.Amount; + break; - case "down": - pos.d += instruction.Amount; - break; + case "down": + pos.d += instruction.Amount; + break; - case "up": - pos.d -= instruction.Amount; - break; - } + case "up": + pos.d -= instruction.Amount; + break; } } @@ -61,27 +62,25 @@ namespace aoc2021 private static void Part2(IEnumerable instructions) { + using var t = new Timer(); Position pos = new(); - using (var t = new Timer()) + long aim = 0; + foreach (var instruction in instructions) { - long aim = 0; - foreach (var instruction in instructions) + switch (instruction.Direction) { - switch (instruction.Direction) - { - case "forward": - pos.h += instruction.Amount; - pos.d += aim * instruction.Amount; - break; + case "forward": + pos.h += instruction.Amount; + pos.d += aim * instruction.Amount; + break; - case "down": - aim += instruction.Amount; - break; + case "down": + aim += instruction.Amount; + break; - case "up": - aim -= instruction.Amount; - break; - } + case "up": + aim -= instruction.Amount; + break; } } diff --git a/src/03.cs b/src/03.cs index f676b67..0477d8e 100644 --- a/src/03.cs +++ b/src/03.cs @@ -4,9 +4,12 @@ { internal static void Go() { + Logger.Log("Day 3"); + Logger.Log("-----"); var lines = File.ReadAllLines("inputs/03.txt"); Part1(lines); Part2(lines); + Logger.Log(""); } private static void Part1(IEnumerable lines) @@ -123,7 +126,7 @@ } } - Logger.Log($"o2*co2 = {o2} * {co2} = {o2 * co2}"); + Logger.Log($"part2: o2*co2 = {o2} * {co2} = {o2 * co2}"); } } }