-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AoC day one, part two - dry run 🎄
- Loading branch information
1 parent
8c314ea
commit 9e206fd
Showing
4 changed files
with
70 additions
and
16 deletions.
There are no files selected for viewing
42 changes: 28 additions & 14 deletions
42
samples/Hussy.Net.Playground/AdventOfCode/Y2024/Datasets.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
samples/Hussy.Net.Playground/AdventOfCode/Y2024/Day1/PartTwo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
namespace Hussy.Net.Playground.AdventOfCode.Y2024; | ||
|
||
public sealed partial class DayOne | ||
{ | ||
[Fact] | ||
public void PartTwo_Example() | ||
{ | ||
const int expectedResult = 31; | ||
RunTest(expectedResult, Datasets.DayOnePartTwoExampleLists, PartTwoDryRun); | ||
} | ||
|
||
[Fact] | ||
public void PartTwo_Actual() | ||
{ | ||
const int expectedResult = 20_719_933; | ||
RunTest(expectedResult, Datasets.DayOneLists, PartTwoDryRun); | ||
} | ||
|
||
private static int PartTwoDryRun( | ||
IEnumerable<int> leftList, | ||
IEnumerable<int> rightList) | ||
{ | ||
var result = 0; | ||
foreach (var left in leftList) | ||
{ | ||
var countInRight = rightList.Count(right => right == left); | ||
result += left * countInRight; | ||
} | ||
|
||
return result; | ||
} | ||
} |