-
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
Showing
9 changed files
with
143 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_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 |
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,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<List<string>> ReadData() | ||
{ | ||
var lines = await File.ReadAllLinesAsync(FILE); | ||
|
||
return lines.ToList(); | ||
} |
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,2 @@ | ||
Time: 49 78 79 80 | ||
Distance: 298 1185 1066 1181 |
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,2 @@ | ||
Time: 7 15 30 | ||
Distance: 9 40 200 |