Initial commit - should have done this on day 1...

This commit is contained in:
2020-12-03 09:59:03 -06:00
commit f2545d7373
10 changed files with 1837 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vs
bin
obj

200
01input.txt Normal file
View File

@ -0,0 +1,200 @@
1895
1504
1660
1775
1743
1607
1267
1133
292
1646
1285
1808
1512
1839
1869
1578
1318
1385
1829
1800
1491
1600
1290
1856
1781
1881
1953
2008
1681
1472
1846
2010
1619
1584
1849
1876
1744
1980
1421
911
1308
1762
1398
1470
1974
1902
1985
2001
1926
1374
1678
1523
1894
1597
1778
1940
1362
1613
1629
1473
1633
1867
1838
1931
1850
1776
1689
1311
1947
1988
1779
1381
1683
1677
1675
1587
767
1401
1412
1544
1484
618
1755
1073
1970
1735
1770
1623
1665
1783
1400
1892
1921
1506
1978
1731
1739
1515
1354
1264
1394
1763
1569
1453
1539
2006
1586
1855
1609
1729
1624
506
1668
1803
1486
1767
1720
1753
1994
1718
1922
1314
1250
1516
1546
1625
1708
1286
1993
1785
491
1705
1924
1752
1888
1651
1604
1750
1547
1481
1704
1851
904
1920
1939
1277
1870
1934
1617
1833
1797
1817
1967
1935
1914
1621
1468
1859
1552
1640
1709
1121
1973
1343
1266
1806
1360
1299
1990
1356
1631
1555
1811
1323
1794
1550
1448
1848
1826
1723
1891
1302
1655
947
1580
1908
1641
1816
1701
1871
1588
1843
1643
1893
1866
1628
1417
1795
1995
1937

1000
02input.txt Normal file

File diff suppressed because it is too large Load Diff

323
03input.txt Normal file
View File

@ -0,0 +1,323 @@
.#....#..##.#..####....#.......
......#..#....#....###......#.#
#..#.....#..............##.#.#.
#.#...#....#...#......##..#..#.
...#..#.##..#..#........###.#.#
...#.#..........#.........##...
...#.#....#.#....#..#......#...
..##.#.....#.......#.###..#..##
..#.......#.......#....##......
....##........##.##...#.###.##.
#.......#.......##..#......#...
..##.............##.#......#...
...#.####....#.....#...##......
.............##.#......#.......
..#...#....#......#....#.......
..#....#..#............#.......
##...#..#........##..#......#..
##........##........#.#.......#
#.......#........#.#..#....###.
.....#..#.#..........##...#....
..##...#......#.#...#..#...#...
##.##...#......#....#....#...#.
#.......#..#.#..#....#..###.#.#
#.............#.#....#..#.#....
...#.......###.#.##.##.#...#..#
.##.......##..##...#..###......
.......#.#.#.#..####..#..#..#..
...##......#.#.##.###....#.###.
###......###......#.#####..#...
..#........##..#..##.##..#...#.
.....##..#...#..#.##.....#.#...
#......#.##....#..##.#....#.#..
##.#.##..#................#....
......#.#....#......##.....#...
..#...##..#..#...#..#.#..#.....
........#.#.#.##...#.#.....#.#.
#.#......#.....##..#...#.......
..#.#......#...........###.....
......##....#....##..#..#.#.#.#
##....#.###...#......#..#...#..
#.#.##....###...####.......#..#
##...........#.....#........#.#
.##.#..#.....#......#.......#..
##..##..###....#.........##....
..#..#..#.##...#.#...#........#
#.##.###...#.......#...........
.........#.................#...
#.##...#.....#..##........#....
....#.#...##...#...........#...
.#.....#.#..#...##..##.....#...
.#.....####....#..##..#........
...#..#......##.#..##.#.#.#..#.
.##.#.....#.....#...#.......##.
......#..#..#......#...####....
.......#......##..#..##.....#..
......#.#..#...#..#.#..........
....##.........#...............
.#....#..##.....#....##.##.....
#.#.....#...#....####....#.#...
#.....#....#.#...#.............
...#..#.....#....##..#..#......
...#.#............#...........#
###.#..#.#......#.....##.....#.
####....#....###.....#..#.#####
.###..#...#.#..#......##.#.#.#.
.....#.##.#....#..##....#..#..#
...#....#...##.....#......#.#..
....#...#....#...#....#.....#.#
.#.....#.....#.#..#......#..#..
..#..##....##.##....#.....##...
#..##...#.##...#..#.#.#.....#..
...#..##.#..#....#.#....######.
..........#..#.....#....#...##.
#.#####.#.###..#.....#.........
#....#......#..#.#.##.##..###..
..#...###.#.#....##.##...##....
.......#....#..#...##......#...
...#.#...#..#.....#..##.#......
###..##...........#............
..#....#.##....#.#..##...#.....
##....#...#....#.....#.#..##...
..............#.##.#..#..##.###
......#..#..#..#.#....###...##.
.#...#..#.#.#....#..........#..
..#.#.....#..#...........#.##..
...#.#......#......#..#..#.#...
...#....#.#.#.....#...#.##..#..
.#.#..#...#........##.......#..
##..........#..#...#....###.#..
#.....###......#..#.#.#....#.#.
..###.......#.#...............#
#....#.....#.#......#..##.##...
#.##.#.#....#..#.#...#.#...#..#
#....#..#...........#.......#..
...#.####.....#.........###.##.
......#..#.....#..........#..#.
#...#.#..####...#...#.#.##...##
.##.........#......#.#.#.......
.......##...##.##....###...##..
...#..#....#..#.#.#.....#.#....
#....#.#.#.......##..###..##...
......#............#.#...#..#..
#.#.....#......#...#.......###.
...#.#................#...#....
.....#......#.#..#...##.#.#...#
#....#.#..#..#..##..#.##..#....
#.................#..#....#....
..#....#.......####....###.....
.#..#.#.#...###..#...#..###....
..#..#.#......#.###..........#.
.....#......#.......##....##.#.
.#....#........#.#.##.#........
#.#..##..#..#.#...####....##...
...#....#.#..#...#..........#..
.#.....#.##....#...##..........
....##....#.....#.....#...#.###
.#...##.#.#..##..#...#.#..#..#.
..#.......#.##.....#.#........#
...#...#.....##..#.#.#....#....
...#.....#.......##.........#.#
.##.....#..#.#...#.#...#.#...#.
...........#...#.###..#...#..#.
#.##........#..###.##...####...
.#.....#.#...##...#..#..#...##.
..#....#..#...#.....#.....##...
..###..#.#.....##........#.##..
.#.#..##........#.##....#..#.##
.####.#..##..#.#..#....##....#.
.##....##...#.#........#.......
....#..#..#...#..#..#..#.#.....
...#......................#....
#.....#.#....#..#..#.#..#....#.
##.....#.....##..........###...
.#..#..............#...##.#.#.#
...#...#.#.............#.#..#.#
..#.....#.......#......#.#.....
.###.#..#..#..#.#..#.....#.....
.....##..##...##.......#....###
.#........###...##..#....##....
#....#.#......##..#....#.##..#.
#....#.#...#........##...###...
.#.....#...#.###....#.##.#.####
###......#....#...#....##..#..#
##....#..###......#...#.#.#....
..........#......##.#..#.......
.#..#......###.........##...#..
....#......#....#.........#.#.#
##.#.#...#.#...#...#..#......#.
....#.##.........#..#.....##.#.
........#...#..#.#.#.#.....##..
..#......#.#.#..#.....##.......
..............#....#....##.#..#
....#.#.....#....#.#.###.#....#
..#..........#..#......#.##..#.
...#...#.#.............#..#....
#.......#..#..##.........##..#.
..##..#............#.....#.....
....#.#..##...#.#..#.........#.
........#.......#.##....#....#.
...#.....#.#.....#.#....#......
..#......##.#.............#.#.#
#.#.............#.#.....#......
.##....##.#.....#....#...##....
.#.#....##....#.....##.........
...#.....#.....#.....#..#.###..
.......#....#...##.#...#...#..#
..#.#.......#...###.#...#....#.
.....###..##....###.#.##.......
....#..................##.#.##.
.#.......###.##...#.#.....#....
....#....##...##.....#.#...#..#
#..#.....#......##...#....#....
#..##.........#.....#...#......
...#..##.......##......#..#####
.#..###.###.#.##........#......
.#...#....#....#.#....#...##...
##........#....#.........##..#.
.#.....##............#.#.......
....#....#...........###.....##
.#......#.#.#..#....#.#.....##.
......#.##.#..##....#.#.#..#...
#....#......#...#..####........
......#..#..##..#.......#.#..#.
##....##.###.#...#.##.#..#.###.
.#.........#...##...#.#......#.
..#.#...........####.#....##.##
.....#.#..##.#...###...#..#.#..
...#..#..##.#...#.....#.##...##
..##......##..........#..###...
.#......##.....#.##....#.#.##.#
...#.......##..##.....#....#...
.##...#...#....#..#............
#..#....#...........#..........
......#...#.#.......#...#.##..#
..#.###..#.....#.....#..#.....#
....#....#..........##....#..#.
.......##.#.#.#......#....#...#
####..#.###........#..#......#.
#........##.#.#.#.............#
.#......#......#..#.##.....#...
.....##.##......##.#.....#.#.#.
.......##.#.....##.......#.#.#.
.#.#..#.#..#.##...#.#....#.#..#
.#..##....#..#...##.......#..#.
.#.#..#.......#................
#........#.#.#......#.#.#.#....
##......#...#..##.#...##.##....
##.#..#...........##...#..###..
......#.####...#........#.#.#..
...#........##..###.#.#...#...#
.#.....##..#......##......###..
..#.#...#......#..#..##.#.....#
#....#..#.#..........#...#.....
.#......#.##..###..#.#....#..##
.......#.......#..#..#......#..
..##.....##.#..#..#.....##.....
........#.##...#.#.#..#..#..#..
...#.######.........#.....#..##
.#.#............#....#.........
#...#....###.#......#.#........
#.........#....#...##..........
....#...........#.###.#...###..
.........#........#.#.#..#...#.
.#.......#.#.....#.#.....#.##..
.....#.......#.....#.#.#.......
#.##..#..##.......#...#......#.
.###.....##...##.#...##.##.#.#.
...#......##..##............#.#
...#......................#..##
#..#..#................#...#...
#..#....#.#.#...##.......#..#..
....#.#..###.##...#..#.###..#..
..#...#....####.#............#.
......#....#.#...#.#.#.........
#...#........#.....##..###.#..#
#....#...#...##...#..#....##...
#..#...#..#.......#.#..##.#..#.
#.#..........#...........##....
.#...###...#......#.......#.#.#
.........#.........#...#...##..
##.#..###......##..#.....#..#..
....##...............#.....#...
.....#.....###.#.....#.#.......
....#..#......###..#..##..#....
......................#.....#..
..#..#...##....##....#........#
..#....#...#...#.......#.....#.
...##.#.#.##......#.#.#.#.####.
.###...#..#......#.#..#........
#..#...##.#..#..##..##....#...#
...#...#..#..#..#........#..##.
.##....#.##.#....#...#.#.#....#
#..#....#..#....#.......##..#.#
...#.#....####...........#...#.
#...#####...#.#..#......#...#.#
.##....#.#.#..#......#..##.....
..........#..#.#.#.....##......
.....#....#..................#.
.........#...#...#....#..###...
.#.#.#....#....................
......##............##.###..#..
#.#...#........####.##..#.#.##.
#........#.#.#.#..#.##.....#...
......####..#.##.......#....#..
.........#...#...#.....#.......
..##.....#...#...#.....##.....#
....#...##....#.....#..#..##.##
..#.........##...##..###..#....
#....#.#.........##.###.#...##.
.##...#....#..#..#.#....##.....
##..#..#..#...........#.##....#
....#..........#...#..#.....#..
........###..#..#.#.#.....##...
#...#...#..###............###..
..#.....#.#.#..#..#.#..#......#
..#...##..#....#...#......#....
#....#........##.....#..##....#
#.....#.#.#..#.......##.#.#.##.
..##...#...#.....#..........#..
##.....#....#......#..........#
......#..#..........#.#..####..
......#...#............##...##.
..#.......##.......#...###.###.
.#..#.#.#...#..##.#......#.#...
.##.....##.#.#...#.##.........#
#.#.######...........#.#####.#.
........#.##...##....##.#.##.#.
....#......#.....#.....###...##
#..............#.#....#.#....#.
....#..###.#.........##.#.#....
..#.#.#..##....####..........#.
...#..#.......#................
...#....#..............#....#..
.....#...#...#....#.#.#..#...#.
......##.............###.##..##
.#...#.#..#......#..#.##.......
##.....#.....#.##...#....#.....
..#..#.#.#.#.#..........#..###.
##..........#........#....#.#..
.....#...#........#.#..###....#
.###.#........#.##......#.#...#
#...##....#....#....##.#.#.....
.....#.#............#..........
..#.##....................#....
.....#..#..#.#..#.##.......#...
.....###......#......##......##
#.....#.#.......##.......#...#.
.#.#...#......#..###...#.....#.
#.#..#...#..##.....#...#.#..#..
.....#.#..........#..#.........
.###..##..##.....#...#...#..##.
#...#.#....#.......##..#.......
###...#.#.#..#.......#......#..
....##........#..........##....
............#....#...........#.
#..#.#....##..#.#..#......##...
.###....##...#....##..........#
.###........#........###.....#.
...#...#.#......#...#....#.....
.###.......#.........#.........
....##.#......#...###......##.#
.###...#..##.....##.......#....
.#.#...#..#.##....#........#...

21
2020.csproj Normal file
View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>_2020</RootNamespace>
</PropertyGroup>
<ItemGroup>
<None Update="01input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="02input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="03input.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

25
2020.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30709.132
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "2020", "2020.csproj", "{08D96689-1ACE-4A53-B36D-047961E071D1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{08D96689-1ACE-4A53-B36D-047961E071D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{08D96689-1ACE-4A53-B36D-047961E071D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{08D96689-1ACE-4A53-B36D-047961E071D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{08D96689-1ACE-4A53-B36D-047961E071D1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2FF21EB1-B41F-4112-B502-EE08C806598C}
EndGlobalSection
EndGlobal

12
Program.cs Normal file
View File

@ -0,0 +1,12 @@
namespace _2020
{
class Program
{
static void Main(string[] args)
{
Q01.Go();
Q02.Go();
Q03.Go();
}
}
}

67
Q01.cs Normal file
View File

@ -0,0 +1,67 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace _2020
{
class Q01
{
public static void Go()
{
var list = GetList();
Part1(list);
Part2(list);
}
static List<int> GetList()
{
var numList = new List<int>();
using var fs = new FileStream("01input.txt", FileMode.Open);
using var sr = new StreamReader(fs);
string line;
while ((line = sr.ReadLine()) != null)
{
if (int.TryParse(line, out int num))
{
numList.Add(num);
}
}
return numList;
}
static void Part1(List<int> numList)
{
for (int i = 0; i < numList.Count; i++)
{
for (int j = i + 1; j < numList.Count; j++)
{
if (numList[i] + numList[j] == 2020)
{
Debug.WriteLine($"Q01Part1: idx {i} + idx {j} = 2020. mult = {numList[i] * numList[j]}");
return;
}
}
}
}
static void Part2(List<int> numList)
{
for (int i = 0; i < numList.Count; i++)
{
for (int j = i + 1; j < numList.Count; j++)
{
for (int k = j + 1; k < numList.Count; k++)
{
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]}");
return;
}
}
}
}
}
}
}

101
Q02.cs Normal file
View File

@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
namespace _2020
{
class Q02
{
public static void Go()
{
var list = GetList();
Part1(list);
Part2(list);
}
struct Q2Entry
{
public int first;
public int second;
public char ch;
public string pw;
}
static List<Q2Entry> GetList()
{
var list = new List<Q2Entry>();
using var fs = new FileStream("02input.txt", FileMode.Open);
using var sr = new StreamReader(fs);
string line;
var rule02 = new Regex("(?<min>[0-9]+)-(?<max>[0-9]+) (?<ch>[a-z]): (?<pw>.+)", RegexOptions.Compiled);
while ((line = sr.ReadLine()) != null)
{
var match = rule02.Match(line);
if (match.Success)
{
list.Add(new Q2Entry()
{
first = Convert.ToInt32(match.Groups["min"].Value),
second = Convert.ToInt32(match.Groups["max"].Value),
ch = match.Groups["ch"].Value[0],
pw = match.Groups["pw"].Value,
});
}
}
return list;
}
static void Part1(List<Q2Entry> list)
{
int numValid = 0;
foreach (var entry in list)
{
var numFound = 0;
foreach (var ch in entry.pw)
{
if (ch == entry.ch)
{
numFound++;
}
}
if (numFound >= entry.first && numFound <= entry.second)
{
numValid++;
}
}
Debug.WriteLine($"Q02Part1: numValid={numValid}");
}
static void Part2(List<Q2Entry> list)
{
int numValid = 0;
foreach (var entry in list)
{
var validConditions = 0;
if (entry.pw.Length >= entry.first && entry.pw[entry.first - 1] == entry.ch)
{
validConditions++;
}
if (entry.pw.Length >= entry.second && entry.pw[entry.second - 1] == entry.ch)
{
validConditions++;
}
if (validConditions == 1)
{
numValid++;
}
}
Debug.WriteLine($"Q02Part2: numValid={numValid}");
}
}
}

85
Q03.cs Normal file
View File

@ -0,0 +1,85 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
namespace _2020
{
class Q03
{
static bool[,] List = null;
public static void Go()
{
List = GetList();
Part1();
Part2();
}
static bool[,] GetList()
{
var list = new List<List<bool>>();
using var fs = new FileStream("03input.txt", FileMode.Open);
using var sr = new StreamReader(fs);
string line;
while ((line = sr.ReadLine()) != null)
{
list.Add(new List<bool>());
for (int i = 0; i < line.Length; i++)
{
list[list.Count - 1].Add(line[i] != '.');
}
}
var retval = new bool[list.Count, list[0].Count];
for (int i = 0; i < list.Count; i++)
{
for (int j = 0; j < list[i].Count; j++)
{
retval[i, j] = list[i][j];
}
}
return retval;
}
static int GetNumTrees(int AddRow, int AddCol)
{
var numRows = List.GetLength(0);
var numCols = List.GetLength(1);
var numTrees = 0;
for (int rowPos = 0, colPos = 0; rowPos < numRows; rowPos += AddRow, colPos += AddCol)
{
if (List[rowPos, colPos % numCols])
{
numTrees++;
}
}
return numTrees;
}
static void Part1()
{
Debug.WriteLine($"Q03Part1: num trees hit = {GetNumTrees(1, 3)}");
}
static void Part2()
{
var treesPerSlope = new List<int>()
{
GetNumTrees(1, 1),
GetNumTrees(1, 3),
GetNumTrees(1, 5),
GetNumTrees(1, 7),
GetNumTrees(2, 1),
};
long multSum = 1;
foreach (var trees in treesPerSlope)
{
multSum *= trees;
}
Debug.WriteLine($"Q03Part2: num trees hit, multiplied = {multSum}");
}
}
}