day 1
This commit is contained in:
9
AOC2023/AOC2023.csproj
Normal file
9
AOC2023/AOC2023.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
10
AOC2023/Problems/Day01/Trebuchet.cs
Normal file
10
AOC2023/Problems/Day01/Trebuchet.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AOC2023.Problems.Day01;
|
||||
public class Trebuchet
|
||||
{
|
||||
}
|
||||
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.4.33110.190
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AdventOfCode", "AdventOfCode\AdventOfCode.csproj", "{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AdventOfCode", "AdventOfCode\AdventOfCode.csproj", "{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AOC2023", "AOC2023\AOC2023.csproj", "{DC0609BD-5AF8-4347-A424-67D9A0AE38A3}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{CAAB9EC2-0787-4CBC-87E3-4529BFB56B3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC0609BD-5AF8-4347-A424-67D9A0AE38A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC0609BD-5AF8-4347-A424-67D9A0AE38A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC0609BD-5AF8-4347-A424-67D9A0AE38A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC0609BD-5AF8-4347-A424-67D9A0AE38A3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
@@ -41,6 +41,7 @@
|
||||
<None Remove="Problems\AOC2022\Day9\input.txt" />
|
||||
<None Remove="Problems\AOC2022\Day9\test.txt" />
|
||||
<None Remove="Problems\AOC2022\Day9\test2.txt" />
|
||||
<None Remove="problems\aoc2023\day1\input.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -53,5 +54,4 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Superpower" Version="3.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
using AdventOfCode.Runner;
|
||||
using AdventOfCode.Runner.Attributes;
|
||||
|
||||
namespace AdventOfCode.Problems.AOC2023.Day0;
|
||||
[ProblemInfo(2023, 0, "Test")]
|
||||
public class TestProblem : Problem
|
||||
{
|
||||
public override void LoadInput()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
public override void CalculatePart2()
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
public override void PrintPart1()
|
||||
{
|
||||
Console.WriteLine("Result");
|
||||
}
|
||||
|
||||
public override void PrintPart2()
|
||||
{
|
||||
Console.WriteLine("Result 2");
|
||||
}
|
||||
}
|
||||
107
AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs
Normal file
107
AdventOfCode/Problems/AOC2023/Day1/Trebuchet.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using AdventOfCode.Runner.Attributes;
|
||||
|
||||
using Superpower.Parsers;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AdventOfCode.Problems.AOC2023.Day1;
|
||||
|
||||
[ProblemInfo(2023, 1, "Trebuchet!?")]
|
||||
public partial class Trebuchet : Problem<int, int>
|
||||
{
|
||||
private string[] _inputData = Array.Empty<string>();
|
||||
|
||||
public override void LoadInput()
|
||||
{
|
||||
_inputData = ReadInputLines();
|
||||
}
|
||||
public override void CalculatePart1()
|
||||
{
|
||||
Part1 = _inputData.Select(GetCalibrationValues)
|
||||
.Select(cv => cv.left * 10 + cv.right)
|
||||
.Sum();
|
||||
}
|
||||
|
||||
private (int left, int right) GetCalibrationValues(string line)
|
||||
{
|
||||
var (left, right) = (0, 0);
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
if (line[i] - '0' >= 10)
|
||||
continue;
|
||||
left = line[i] - '0';
|
||||
break;
|
||||
}
|
||||
for (int i = line.Length - 1; i >= 0; i--)
|
||||
{
|
||||
if (line[i] - '0' >= 10)
|
||||
continue;
|
||||
right = line[i] - '0';
|
||||
break;
|
||||
}
|
||||
return (left, right);
|
||||
}
|
||||
|
||||
private readonly (string word, int value)[] numberWords = new []
|
||||
{
|
||||
("one", 1),
|
||||
("two", 2),
|
||||
("three", 3),
|
||||
("four", 4),
|
||||
("five", 5),
|
||||
("six", 6),
|
||||
("seven", 7),
|
||||
("eight", 8),
|
||||
("nine", 9)
|
||||
};
|
||||
|
||||
public override void CalculatePart2()
|
||||
{
|
||||
Part2 = _inputData.Select(GetNamedCalibrationValues)
|
||||
.Select(cv => cv.left * 10 + cv.right)
|
||||
.Sum();
|
||||
}
|
||||
|
||||
private (int left, int right) GetNamedCalibrationValues(string line)
|
||||
{
|
||||
var (left, right) = (0, 0);
|
||||
for (int i = 0; i < line.Length; i++)
|
||||
{
|
||||
var word = numberWords.FirstOrDefault(v => line[i..].StartsWith(v.word), (word: "", value: -1)).value;
|
||||
if (word != -1)
|
||||
{
|
||||
left = word;
|
||||
break;
|
||||
}else if(line[i] - '0' >= 10)
|
||||
continue;
|
||||
|
||||
left = line[i] - '0';
|
||||
break;
|
||||
}
|
||||
for (int i = line.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var word = numberWords.FirstOrDefault(v => line[..(i + 1)].EndsWith(v.word), (word: "", value: -1)).value;
|
||||
if (word != -1)
|
||||
{
|
||||
right = word;
|
||||
break;
|
||||
}
|
||||
else if (line[i] - '0' >= 10)
|
||||
continue;
|
||||
|
||||
right = line[i] - '0';
|
||||
break;
|
||||
}
|
||||
return (left, right);
|
||||
}
|
||||
|
||||
|
||||
[GeneratedRegex("(?<1>one)|(?<2>two)|(?<3>three)|(?<4>four)|(?<5>five)|(?<6>six)|(?<7>seven)|(?<8>eight)|(?<9>nine)|(?<1>1)|(?<2>2)|(?<3>3)|(?<4>4)|(?<5>5)|(?<6>6)|(?<7>7)|(?<8>8)|(?<9>9)")]
|
||||
public static partial Regex ParseNumbers();
|
||||
|
||||
}
|
||||
1000
AdventOfCode/Problems/AOC2023/Day1/input.txt
Normal file
1000
AdventOfCode/Problems/AOC2023/Day1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user