Tweak output formatting

This commit is contained in:
2021-12-03 10:09:11 -06:00
parent 12b004c724
commit a0e5125a23
2 changed files with 33 additions and 31 deletions

View File

@ -4,6 +4,8 @@ namespace aoc2021
{ {
internal static void Go() internal static void Go()
{ {
Logger.Log("Day 2");
Logger.Log("-----");
var lines = File.ReadAllLines("inputs/02.txt"); var lines = File.ReadAllLines("inputs/02.txt");
var instructions = new List<Instruction>(); var instructions = new List<Instruction>();
foreach (var instruction in lines) foreach (var instruction in lines)
@ -18,6 +20,7 @@ namespace aoc2021
Part1(instructions); Part1(instructions);
Part2(instructions); Part2(instructions);
Logger.Log("");
} }
struct Instruction struct Instruction
@ -34,25 +37,23 @@ namespace aoc2021
private static void Part1(IEnumerable<Instruction> instructions) private static void Part1(IEnumerable<Instruction> instructions)
{ {
using var t = new Timer();
Position pos = new(); 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;
case "forward": break;
pos.h += instruction.Amount;
break;
case "down": case "down":
pos.d += instruction.Amount; pos.d += instruction.Amount;
break; break;
case "up": case "up":
pos.d -= instruction.Amount; pos.d -= instruction.Amount;
break; break;
}
} }
} }
@ -61,27 +62,25 @@ namespace aoc2021
private static void Part2(IEnumerable<Instruction> instructions) private static void Part2(IEnumerable<Instruction> instructions)
{ {
using var t = new Timer();
Position pos = new(); Position pos = new();
using (var t = new Timer()) long aim = 0;
foreach (var instruction in instructions)
{ {
long aim = 0; switch (instruction.Direction)
foreach (var instruction in instructions)
{ {
switch (instruction.Direction) case "forward":
{ pos.h += instruction.Amount;
case "forward": pos.d += aim * instruction.Amount;
pos.h += instruction.Amount; break;
pos.d += aim * instruction.Amount;
break;
case "down": case "down":
aim += instruction.Amount; aim += instruction.Amount;
break; break;
case "up": case "up":
aim -= instruction.Amount; aim -= instruction.Amount;
break; break;
}
} }
} }

View File

@ -4,9 +4,12 @@
{ {
internal static void Go() internal static void Go()
{ {
Logger.Log("Day 3");
Logger.Log("-----");
var lines = File.ReadAllLines("inputs/03.txt"); var lines = File.ReadAllLines("inputs/03.txt");
Part1(lines); Part1(lines);
Part2(lines); Part2(lines);
Logger.Log("");
} }
private static void Part1(IEnumerable<string> lines) private static void Part1(IEnumerable<string> lines)
@ -123,7 +126,7 @@
} }
} }
Logger.Log($"o2*co2 = {o2} * {co2} = {o2 * co2}"); Logger.Log($"part2: o2*co2 = {o2} * {co2} = {o2 * co2}");
} }
} }
} }