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()
{
Logger.Log("Day 2");
Logger.Log("-----");
var lines = File.ReadAllLines("inputs/02.txt");
var instructions = new List<Instruction>();
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<Instruction> 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<Instruction> 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;
}
}

View File

@ -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<string> lines)
@ -123,7 +126,7 @@
}
}
Logger.Log($"o2*co2 = {o2} * {co2} = {o2 * co2}");
Logger.Log($"part2: o2*co2 = {o2} * {co2} = {o2 * co2}");
}
}
}