Convert to a logger so I can see results in terminal or IDE
This commit is contained in:
11
Program.cs
11
Program.cs
@ -16,7 +16,16 @@
|
||||
Q09.Go();
|
||||
Q10.Go();
|
||||
Q11.Go();
|
||||
System.Diagnostics.Debug.WriteLine($"Total time={(System.DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Total time={(System.DateTime.Now - start).TotalMilliseconds}ms");
|
||||
}
|
||||
}
|
||||
|
||||
class Util
|
||||
{
|
||||
internal static void Log(string msg)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine(msg);
|
||||
System.Console.WriteLine(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
Q01.cs
5
Q01.cs
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace _2020
|
||||
@ -39,7 +38,7 @@ namespace _2020
|
||||
{
|
||||
if (numList[i] + numList[j] == 2020)
|
||||
{
|
||||
Debug.WriteLine($"Q01Part1: idx {i} + idx {j} = 2020. mult = {numList[i] * numList[j]}");
|
||||
Util.Log($"Q01Part1: idx {i} + idx {j} = 2020. mult = {numList[i] * numList[j]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -56,7 +55,7 @@ namespace _2020
|
||||
{
|
||||
if (numList[i] + numList[j] + numList[k] == 2020)
|
||||
{
|
||||
Debug.WriteLine($"Q01Part2: idx {i} + idx {j} + idx {k} = 2020. mult = {numList[i] * numList[j] * numList[k]}");
|
||||
Util.Log($"Q01Part2: idx {i} + idx {j} + idx {k} = 2020. mult = {numList[i] * numList[j] * numList[k]}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
5
Q02.cs
5
Q02.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -70,7 +69,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q02Part1: numValid={numValid}");
|
||||
Util.Log($"Q02Part1: numValid={numValid}");
|
||||
}
|
||||
|
||||
static void Part2(List<Q2Entry> list)
|
||||
@ -95,7 +94,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q02Part2: numValid={numValid}");
|
||||
Util.Log($"Q02Part2: numValid={numValid}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
Q03.cs
5
Q03.cs
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace _2020
|
||||
@ -60,7 +59,7 @@ namespace _2020
|
||||
|
||||
static void Part1()
|
||||
{
|
||||
Debug.WriteLine($"Q03Part1: num trees hit = {GetNumTrees(1, 3)}");
|
||||
Util.Log($"Q03Part1: num trees hit = {GetNumTrees(1, 3)}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -79,7 +78,7 @@ namespace _2020
|
||||
{
|
||||
multSum *= trees;
|
||||
}
|
||||
Debug.WriteLine($"Q03Part2: num trees hit, multiplied = {multSum}");
|
||||
Util.Log($"Q03Part2: num trees hit, multiplied = {multSum}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
Q04.cs
5
Q04.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
@ -66,7 +65,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q04Part1: num valid={numValid}");
|
||||
Util.Log($"Q04Part1: num valid={numValid}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -139,7 +138,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q04Part2: num valid={numValid}");
|
||||
Util.Log($"Q04Part2: num valid={numValid}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
Q05.cs
5
Q05.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace _2020
|
||||
@ -98,7 +97,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q05Part1: highest id={highestId}");
|
||||
Util.Log($"Q05Part1: highest id={highestId}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -126,7 +125,7 @@ namespace _2020
|
||||
throw new Exception("Found multiple seats");
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q05Part2: your seat={myId}");
|
||||
Util.Log($"Q05Part2: your seat={myId}");
|
||||
foundMine = true;
|
||||
}
|
||||
|
||||
|
8
Q06.cs
8
Q06.cs
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
@ -63,13 +61,13 @@ namespace _2020
|
||||
static void Part1()
|
||||
{
|
||||
var sum = list.Sum(x => x.answers.Keys.Count);
|
||||
Debug.WriteLine($"Q06Part1: sum={sum}");
|
||||
Util.Log($"Q06Part1: sum={sum}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
{
|
||||
var sum = list.Sum(x => x.answers.Sum(y => y.Value == x.numInGroup ? 1 : 0));
|
||||
Debug.WriteLine($"Q06Part2: sum={sum}");
|
||||
Util.Log($"Q06Part2: sum={sum}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
Q07.cs
5
Q07.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@ -100,7 +99,7 @@ namespace _2020
|
||||
}
|
||||
|
||||
var result = totalContain.Distinct();
|
||||
Debug.WriteLine($"Q07Part1: total contain={result.Count()}");
|
||||
Util.Log($"Q07Part1: total contain={result.Count()}");
|
||||
}
|
||||
|
||||
static int GetNumBagsContainedIn(BagType bag)
|
||||
@ -122,7 +121,7 @@ namespace _2020
|
||||
|
||||
int bagsNeeded = GetNumBagsContainedIn(shinyGoldBag);
|
||||
|
||||
Debug.WriteLine($"Q07Part2: bags needed={bagsNeeded}");
|
||||
Util.Log($"Q07Part2: bags needed={bagsNeeded}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
7
Q08.cs
7
Q08.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
@ -82,7 +81,7 @@ namespace _2020
|
||||
throw new Exception("Exited normally - shouldn't have");
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q08Part1: accum value={result.Item1}");
|
||||
Util.Log($"Q08Part1: accum value={result.Item1}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -120,7 +119,7 @@ namespace _2020
|
||||
throw new Exception("nothing worked");
|
||||
}
|
||||
|
||||
Debug.WriteLine($"changing {instructionToChange} to {instructionToReplace} didn't work - flipping");
|
||||
Util.Log($"changing {instructionToChange} to {instructionToReplace} didn't work - flipping");
|
||||
var tmp = instructionToChange;
|
||||
instructionToChange = instructionToReplace;
|
||||
instructionToReplace = tmp;
|
||||
@ -144,7 +143,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q08Part2: accum value={accum}");
|
||||
Util.Log($"Q08Part2: accum value={accum}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
Q09.cs
13
Q09.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace _2020
|
||||
@ -15,15 +14,15 @@ namespace _2020
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
MakeList();
|
||||
Debug.WriteLine($"Q09 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q09 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
var p1start = DateTime.Now;
|
||||
Part1();
|
||||
Debug.WriteLine($"Q09 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q09 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
var p2start = DateTime.Now;
|
||||
Part2();
|
||||
Debug.WriteLine($"Q09 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q09 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
|
||||
Debug.WriteLine($"Q09 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q09 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
static void MakeList()
|
||||
@ -73,7 +72,7 @@ namespace _2020
|
||||
|
||||
if (idx >= 0)
|
||||
{
|
||||
Debug.WriteLine($"Q09Part1: found invalid number={list[idx]}");
|
||||
Util.Log($"Q09Part1: found invalid number={list[idx]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -127,7 +126,7 @@ namespace _2020
|
||||
}
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q09Part2: encryption weakness={smallestInRange + largestInRange}");
|
||||
Util.Log($"Q09Part2: encryption weakness={smallestInRange + largestInRange}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
Q10.cs
13
Q10.cs
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace _2020
|
||||
@ -14,15 +13,15 @@ namespace _2020
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
MakeList();
|
||||
Debug.WriteLine($"Q10 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q10 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
var p1start = DateTime.Now;
|
||||
Part1();
|
||||
Debug.WriteLine($"Q10 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q10 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
var p2start = DateTime.Now;
|
||||
Part2();
|
||||
Debug.WriteLine($"Q10 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q10 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
|
||||
Debug.WriteLine($"Q10 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q10 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
static void MakeList()
|
||||
@ -47,7 +46,7 @@ namespace _2020
|
||||
diffs[sortedList[i] - sortedList[i - 1] - 1]++;
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q10Part1: device joltage={sortedList[^1]}, diffs by 1={diffs[0]}, diffs by 3={diffs[2]}, multiplied={diffs[0] * diffs[2]}");
|
||||
Util.Log($"Q10Part1: device joltage={sortedList[^1]}, diffs by 1={diffs[0]}, diffs by 3={diffs[2]}, multiplied={diffs[0] * diffs[2]}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -72,7 +71,7 @@ namespace _2020
|
||||
pathsToIndices.Add(pathLen);
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q10Part2: combinations={pathsToIndices[^1]}");
|
||||
Util.Log($"Q10Part2: combinations={pathsToIndices[^1]}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
Q11.cs
13
Q11.cs
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -23,15 +22,15 @@ namespace _2020
|
||||
{
|
||||
var start = DateTime.Now;
|
||||
MakeList();
|
||||
Debug.WriteLine($"Q11 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q11 MakeList took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
var p1start = DateTime.Now;
|
||||
Part1();
|
||||
Debug.WriteLine($"Q11 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q11 part1 took {(DateTime.Now - p1start).TotalMilliseconds}ms");
|
||||
var p2start = DateTime.Now;
|
||||
Part2();
|
||||
Debug.WriteLine($"Q11 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q11 part2 took {(DateTime.Now - p2start).TotalMilliseconds}ms");
|
||||
|
||||
Debug.WriteLine($"Q11 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
Util.Log($"Q11 took {(DateTime.Now - start).TotalMilliseconds}ms");
|
||||
}
|
||||
|
||||
static void MakeList()
|
||||
@ -241,7 +240,7 @@ namespace _2020
|
||||
Array.Copy(nextState, currState, numRows * numCols);
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q11Part1: stabilized after {rounds - 1} rounds, total occupied={GetNumOccupied(currState)}");
|
||||
Util.Log($"Q11Part1: stabilized after {rounds - 1} rounds, total occupied={GetNumOccupied(currState)}");
|
||||
}
|
||||
|
||||
static void Part2()
|
||||
@ -278,7 +277,7 @@ namespace _2020
|
||||
Array.Copy(nextState, currState, numRows * numCols);
|
||||
}
|
||||
|
||||
Debug.WriteLine($"Q11Part2: stabilized after {rounds - 1} rounds, total occupied={GetNumOccupied(currState)}");
|
||||
Util.Log($"Q11Part2: stabilized after {rounds - 1} rounds, total occupied={GetNumOccupied(currState)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user