From 1bb416af148b8bc4dd21b2e202a9f006ec840fae Mon Sep 17 00:00:00 2001 From: Tom Strausbaugh Date: Sun, 10 Dec 2023 09:13:26 -0500 Subject: [PATCH] Day 6 completed --- Day_6/.idea/.idea.Day_6/.idea/.gitignore | 13 ++++ Day_6/.idea/.idea.Day_6/.idea/encodings.xml | 4 + Day_6/.idea/.idea.Day_6/.idea/indexLayout.xml | 8 ++ Day_6/.idea/.idea.Day_6/.idea/vcs.xml | 6 ++ Day_6/Day_6.sln | 16 ++++ Day_6/Day_6/Day_6.csproj | 19 +++++ Day_6/Day_6/Program.cs | 73 +++++++++++++++++++ Day_6/Day_6/data.txt | 2 + Day_6/Day_6/test.txt | 2 + 9 files changed, 143 insertions(+) create mode 100644 Day_6/.idea/.idea.Day_6/.idea/.gitignore create mode 100644 Day_6/.idea/.idea.Day_6/.idea/encodings.xml create mode 100644 Day_6/.idea/.idea.Day_6/.idea/indexLayout.xml create mode 100644 Day_6/.idea/.idea.Day_6/.idea/vcs.xml create mode 100644 Day_6/Day_6.sln create mode 100644 Day_6/Day_6/Day_6.csproj create mode 100644 Day_6/Day_6/Program.cs create mode 100644 Day_6/Day_6/data.txt create mode 100644 Day_6/Day_6/test.txt diff --git a/Day_6/.idea/.idea.Day_6/.idea/.gitignore b/Day_6/.idea/.idea.Day_6/.idea/.gitignore new file mode 100644 index 0000000..e13e5b0 --- /dev/null +++ b/Day_6/.idea/.idea.Day_6/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/.idea.Day_6.iml +/projectSettingsUpdater.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/Day_6/.idea/.idea.Day_6/.idea/encodings.xml b/Day_6/.idea/.idea.Day_6/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/Day_6/.idea/.idea.Day_6/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Day_6/.idea/.idea.Day_6/.idea/indexLayout.xml b/Day_6/.idea/.idea.Day_6/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/Day_6/.idea/.idea.Day_6/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Day_6/.idea/.idea.Day_6/.idea/vcs.xml b/Day_6/.idea/.idea.Day_6/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Day_6/.idea/.idea.Day_6/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Day_6/Day_6.sln b/Day_6/Day_6.sln new file mode 100644 index 0000000..57c6dee --- /dev/null +++ b/Day_6/Day_6.sln @@ -0,0 +1,16 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Day_6", "Day_6\Day_6.csproj", "{B72F9692-1289-411D-BC2B-9DAB18435429}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B72F9692-1289-411D-BC2B-9DAB18435429}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B72F9692-1289-411D-BC2B-9DAB18435429}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B72F9692-1289-411D-BC2B-9DAB18435429}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B72F9692-1289-411D-BC2B-9DAB18435429}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Day_6/Day_6/Day_6.csproj b/Day_6/Day_6/Day_6.csproj new file mode 100644 index 0000000..3757728 --- /dev/null +++ b/Day_6/Day_6/Day_6.csproj @@ -0,0 +1,19 @@ + + + + Exe + net7.0 + enable + enable + + + + + Always + + + Always + + + + diff --git a/Day_6/Day_6/Program.cs b/Day_6/Day_6/Program.cs new file mode 100644 index 0000000..5ac0add --- /dev/null +++ b/Day_6/Day_6/Program.cs @@ -0,0 +1,73 @@ + +const string FILE = "data.txt"; + +var lines = await ReadData(); +var times = lines[0] + .Split(":")[1] + .Trim() + .Split(" ", StringSplitOptions.RemoveEmptyEntries) + .Select(s => int.Parse(s)) + .ToList(); +var distances = lines[1] + .Split(":")[1] + .Trim() + .Split(" ", StringSplitOptions.RemoveEmptyEntries) + .Select(s => int.Parse(s)) + .ToList(); + +//var winningOptions = new int[times.Count]; + +// for (int i = 0; i < times.Count; i++) +// { +// var time = times[i]; +// var recordDistance = distances[i]; +// var lastDistance = Int32.MinValue; +// var winningOption = 0; +// +// for (int j = 2; j < time; j++) +// { +// var remaingingTime = time - j; +// var distance = j * remaingingTime; +// +// if (distance < lastDistance && distance < recordDistance) +// break; +// +// if (distance > recordDistance) +// winningOption++; +// +// lastDistance = distance; +// } +// +// winningOptions[i] = winningOption; +// } + +var winningOptions = 0; + +ulong recordDistance = 298118510661181; +ulong time = 49787980; +var lastDistance = Int128.MinValue; + +for (ulong j = 2; j < time; j++) +{ + var remaingingTime = time - j; + ulong distance = j * remaingingTime; + + if (distance < lastDistance && distance < recordDistance) + break; + + if (distance > recordDistance) + winningOptions++; + + lastDistance = distance; + //Console.WriteLine($"DISTANCE: {distance}\t\tRECORD_DISTANCE: {recordDistance}"); +} + + +Console.WriteLine(winningOptions); + +async Task> ReadData() +{ + var lines = await File.ReadAllLinesAsync(FILE); + + return lines.ToList(); +} \ No newline at end of file diff --git a/Day_6/Day_6/data.txt b/Day_6/Day_6/data.txt new file mode 100644 index 0000000..46f0492 --- /dev/null +++ b/Day_6/Day_6/data.txt @@ -0,0 +1,2 @@ +Time: 49 78 79 80 +Distance: 298 1185 1066 1181 \ No newline at end of file diff --git a/Day_6/Day_6/test.txt b/Day_6/Day_6/test.txt new file mode 100644 index 0000000..b39f49d --- /dev/null +++ b/Day_6/Day_6/test.txt @@ -0,0 +1,2 @@ +Time: 7 15 30 +Distance: 9 40 200 \ No newline at end of file