Day 1 Part 1

This commit is contained in:
2023-12-01 13:14:26 -05:00
commit bbfb7017f3
5 changed files with 1487 additions and 0 deletions

46
day1/part1/Program.cs Normal file
View File

@@ -0,0 +1,46 @@
using Spectre.Console;
namespace part1;
class Program
{
static void Main(string[] args)
{
int sum = 0;
string letters = "abcdefghijklmnopqrstuvwxyz";
var table = new Table();
table.AddColumn(new TableColumn("String"));
table.AddColumn(new TableColumn("First"));
table.AddColumn(new TableColumn("Last"));
table.AddColumn(new TableColumn("Result"));
StreamReader sr = new StreamReader("input");
String line = sr.ReadLine();
//Continue to read until you reach end of file
while (line != null)
{
line = line.ToLower();
List<int> ints = [];
for (int i = 0; i < line.Length; i++) {
if(Char.IsDigit(line[i])) {
ints.Add(Int32.Parse(line[i].ToString()));
}
}
int result = (ints.First() * 10) + ints.Last();
table.AddRow(line, ints.First().ToString(), ints.Last().ToString(), result.ToString());
sum += result;
line = sr.ReadLine();
}
//close the file
sr.Close();
AnsiConsole.Write(table);
Console.WriteLine($"Total Sum: {sum}");
}
}

1000
day1/part1/input Normal file

File diff suppressed because it is too large Load Diff

18
day1/part1/part1.csproj Normal file
View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Update="input" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Spectre.Console" Version="0.48.0" />
</ItemGroup>
</Project>

25
day1/part1/part1.sln Normal file
View File

@@ -0,0 +1,25 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "part1", "part1.csproj", "{C09F35B1-BEBD-40E5-A3A9-21C31B5142F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C09F35B1-BEBD-40E5-A3A9-21C31B5142F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C09F35B1-BEBD-40E5-A3A9-21C31B5142F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C09F35B1-BEBD-40E5-A3A9-21C31B5142F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C09F35B1-BEBD-40E5-A3A9-21C31B5142F8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D4410252-496A-49DA-8EF3-4B0141DE8941}
EndGlobalSection
EndGlobal