Initial Days
This commit is contained in:
20
Day1/Day1.csproj
Normal file
20
Day1/Day1.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="TUnit" Version="0.4.51" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="input.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
21
Day1/Program.cs
Normal file
21
Day1/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
string[] inputs = File.ReadAllLines("input.txt");
|
||||
|
||||
var a = new List<int>();
|
||||
var b = new List<int>();
|
||||
foreach (string input in inputs)
|
||||
{
|
||||
string[] tokens = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
|
||||
a.Add(int.Parse(tokens[0]));
|
||||
b.Add(int.Parse(tokens[1]));
|
||||
}
|
||||
|
||||
a = a.OrderBy(x => x).ToList();
|
||||
b = b.OrderBy(x => x).ToList();
|
||||
|
||||
int totalDistance = a.Select((t, i) => Math.Abs(t - b[i])).Sum();
|
||||
|
||||
Console.WriteLine(totalDistance);
|
||||
|
||||
var aBucket = a.GroupBy(x => x);
|
||||
var star2 = aBucket.Select(bucket => bucket.Key * b.Count(x => x == bucket.Key) * bucket.Count()).Sum();
|
||||
Console.WriteLine(star2);
|
||||
Reference in New Issue
Block a user