-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Strausbaugh
committed
Dec 8, 2023
1 parent
4994697
commit a478672
Showing
9 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day_4", "Day_4\Day_4.csproj", "{F3B089A1-1DCA-4655-99E0-32E1237FFF21}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{F3B089A1-1DCA-4655-99E0-32E1237FFF21}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{F3B089A1-1DCA-4655-99E0-32E1237FFF21}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{F3B089A1-1DCA-4655-99E0-32E1237FFF21}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{F3B089A1-1DCA-4655-99E0-32E1237FFF21}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
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,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Update="test.txt"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
<None Update="data.txt"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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,56 @@ | ||
| ||
const string DATA_FILE = "data.txt"; | ||
|
||
var lines = ReadData(); | ||
var card_copies = new int[lines.Count()]; | ||
Array.Fill(card_copies, 1); | ||
|
||
var sum = 0; | ||
var card_sum = 0; | ||
|
||
for (var i = 0; i < lines.Count(); i++) | ||
{ | ||
var score = 0; | ||
|
||
var card = lines[i].Split(":", StringSplitOptions.RemoveEmptyEntries); | ||
var numbers = card[1].Split("|", StringSplitOptions.RemoveEmptyEntries); | ||
var win_numbers = numbers[0].Split(" ", StringSplitOptions.RemoveEmptyEntries); | ||
var player_numbers = numbers[1].Split(" ", StringSplitOptions.RemoveEmptyEntries); | ||
|
||
var matches = player_numbers.Where(p => win_numbers.Contains(p)); | ||
|
||
switch (matches.Count()) | ||
{ | ||
case 0: | ||
score = 0; | ||
break; | ||
case 1: | ||
score = 1; | ||
break; | ||
default: | ||
score = (int)Math.Pow(2, matches.Count() - 1); | ||
break; | ||
} | ||
|
||
sum += score; | ||
|
||
for (int j = 0; j < card_copies[i]; j++) | ||
{ | ||
for (int k = 1; k <= matches.Count(); k++) | ||
{ | ||
card_copies[(i + k) >= card_copies.Length ? card_copies.Length - 1 : i + k] += 1; | ||
} | ||
} | ||
|
||
card_sum += card_copies[i]; | ||
} | ||
|
||
Console.WriteLine($"Total Score is {sum}"); | ||
Console.WriteLine($"Total Number of Card Copies is {card_sum}"); // 8063216 | ||
|
||
List<string> ReadData() | ||
{ | ||
var data = File.ReadAllLines(DATA_FILE).ToList(); | ||
|
||
return data; | ||
} |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53 | ||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19 | ||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1 | ||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83 | ||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36 | ||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11 |