commit cb1aeea711c1a04c8243c40c632dfa486ce14707 Author: Claudiu Farcas Date: Wed Dec 14 20:34:09 2022 +0200 init current diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8dd4607 --- /dev/null +++ b/.gitignore @@ -0,0 +1,398 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..1a7d55f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/day14/day14/bin/Debug/net6.0/day14.dll", + "args": [], + "cwd": "${workspaceFolder}/day14/day14", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ed1a9e5 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.enableFiletypes": [ + "!plaintext" + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..9bab9e7 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/day14/day14/day14.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/day14/day14/day14.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/day14/day14/day14.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..61e7fc0 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Advent of code 2022 + +My C# solutions for + diff --git a/aoc_2022.sln b/aoc_2022.sln new file mode 100644 index 0000000..dfdb9d0 --- /dev/null +++ b/aoc_2022.sln @@ -0,0 +1,242 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day01", "day01", "{E7C08291-5975-4F77-BA54-06CAF8EC64EE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day01", "day01\day01\day01.csproj", "{DD750DA9-951E-4CF6-91A0-629B65FF6AD6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day01.test", "day01\day01.test\day01.test.csproj", "{5087F9F3-D6AC-450E-A075-67643266BC3B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day02", "day02", "{8BB7FA2C-0E5C-4407-8773-BA9E970ACA11}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day02", "day02\day02\day02.csproj", "{710A4F6C-FC52-4BD3-8163-62542C449B3D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day02.test", "day02\day02.test\day02.test.csproj", "{1A72FFD5-3B27-4C30-88A2-1CB2B8539288}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day03", "day03", "{40E8A91B-A6A7-45EF-9D32-28E7B78109A2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day03", "day03\day03\day03.csproj", "{7FF6971A-0B77-4E38-ADA3-4A2C07561A6B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day03.test", "day03\day03.test\day03.test.csproj", "{E592A289-1AFE-47D8-88CB-89B99DCBC33F}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day04", "day04", "{B697D39A-8F74-4F4F-8B11-118065033B21}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day04", "day04\day04\day04.csproj", "{39F5BF2C-E541-498A-8305-6885DE7EB221}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day04.test", "day04\day04.test\day04.test.csproj", "{67485CAC-49F6-4D25-9EC9-017447454C3B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day05", "day05", "{C6F14DE8-E27C-4689-B289-B7FEB2E6342C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day05", "day05\day05\day05.csproj", "{5B859B2B-FE4D-4263-ADFA-6E89D4015AEE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day05.test", "day05\day05.test\day05.test.csproj", "{4BCB8665-5BBB-487B-B463-13474598E59D}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day06", "day06", "{CB650B2B-DA2F-4FC3-AE86-2CC9BDAE5812}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day06", "day06\day06\day06.csproj", "{3C479404-BFF4-4416-9D72-D1628C98A7F4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day06.test", "day06\day06.test\day06.test.csproj", "{63C04643-D358-4346-9FC5-76177A1A85D0}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day07", "day07", "{A641F6D9-6528-4B22-8C47-635AD09EF1AF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day07", "day07\day07\day07.csproj", "{1E0D1E2E-4735-423A-8940-5A560F92B105}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day07.test", "day07\day07.test\day07.test.csproj", "{B6C0B40B-16E4-497A-92A9-6589568DA54C}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day08", "day08", "{AC807DDB-75C0-4DCA-9568-26548D8360FE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day08", "day08\day08\day08.csproj", "{E9481EA8-3326-4D93-8D91-2E67354272F6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day08.test", "day08\day08.test\day08.test.csproj", "{6432958B-E03E-45DE-823E-95105010EEEC}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day09", "day09", "{D95CB972-5D41-49F9-BFEE-B48479AEEE85}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day09", "day09\day09\day09.csproj", "{5B82691D-3404-42A8-90CF-C1FD96367370}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day09.test", "day09\day09.test\day09.test.csproj", "{ADE5E4DC-8B14-46EC-8248-26C4DC3AD502}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day10", "day10", "{786D928F-5694-4460-9268-4B69864DB471}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day10", "day10\day10\day10.csproj", "{BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day10.test", "day10\day10.test\day10.test.csproj", "{A372B755-E329-4DFA-816D-DBE71A4FE679}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day11", "day11", "{97C51EF3-0E68-425A-8CBF-99784C1178A3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day11", "day11\day11\day11.csproj", "{EB1954CC-3093-44A0-9A0D-2F39A51A8846}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day11.test", "day11\day11.test\day11.test.csproj", "{CE1E9940-66A1-4E06-BFA2-25F3988E3BEB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day12", "day12", "{E9451070-74DE-47A3-978F-737711877891}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day12", "day12\day12\day12.csproj", "{404DAE0A-17CE-4049-B276-F1695B7114B3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day12.test", "day12\day12.test\day12.test.csproj", "{FB67BE8B-09DA-497F-868E-AC1729C7BF96}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day13", "day13", "{07E3D4B8-F361-4467-B27C-42B6D5427988}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day13", "day13\day13\day13.csproj", "{2F22755A-64F6-4281-8DA6-8F00871FC9EF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day13.test", "day13\day13.test\day13.test.csproj", "{A7209996-5CB1-4D1F-AFC4-F50EE465FD98}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "day14", "day14", "{94CABFE2-1106-44CA-9722-54E3C2A77F21}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day14", "day14\day14\day14.csproj", "{8DF3A058-7F98-4F2F-9601-32BE3312857C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "day14.test", "day14\day14.test\day14.test.csproj", "{82F6593B-3354-4246-B18E-B25A9DDEDBCC}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DD750DA9-951E-4CF6-91A0-629B65FF6AD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DD750DA9-951E-4CF6-91A0-629B65FF6AD6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DD750DA9-951E-4CF6-91A0-629B65FF6AD6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DD750DA9-951E-4CF6-91A0-629B65FF6AD6}.Release|Any CPU.Build.0 = Release|Any CPU + {5087F9F3-D6AC-450E-A075-67643266BC3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5087F9F3-D6AC-450E-A075-67643266BC3B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5087F9F3-D6AC-450E-A075-67643266BC3B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5087F9F3-D6AC-450E-A075-67643266BC3B}.Release|Any CPU.Build.0 = Release|Any CPU + {710A4F6C-FC52-4BD3-8163-62542C449B3D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {710A4F6C-FC52-4BD3-8163-62542C449B3D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {710A4F6C-FC52-4BD3-8163-62542C449B3D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {710A4F6C-FC52-4BD3-8163-62542C449B3D}.Release|Any CPU.Build.0 = Release|Any CPU + {1A72FFD5-3B27-4C30-88A2-1CB2B8539288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1A72FFD5-3B27-4C30-88A2-1CB2B8539288}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1A72FFD5-3B27-4C30-88A2-1CB2B8539288}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1A72FFD5-3B27-4C30-88A2-1CB2B8539288}.Release|Any CPU.Build.0 = Release|Any CPU + {7FF6971A-0B77-4E38-ADA3-4A2C07561A6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FF6971A-0B77-4E38-ADA3-4A2C07561A6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FF6971A-0B77-4E38-ADA3-4A2C07561A6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FF6971A-0B77-4E38-ADA3-4A2C07561A6B}.Release|Any CPU.Build.0 = Release|Any CPU + {E592A289-1AFE-47D8-88CB-89B99DCBC33F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E592A289-1AFE-47D8-88CB-89B99DCBC33F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E592A289-1AFE-47D8-88CB-89B99DCBC33F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E592A289-1AFE-47D8-88CB-89B99DCBC33F}.Release|Any CPU.Build.0 = Release|Any CPU + {39F5BF2C-E541-498A-8305-6885DE7EB221}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {39F5BF2C-E541-498A-8305-6885DE7EB221}.Debug|Any CPU.Build.0 = Debug|Any CPU + {39F5BF2C-E541-498A-8305-6885DE7EB221}.Release|Any CPU.ActiveCfg = Release|Any CPU + {39F5BF2C-E541-498A-8305-6885DE7EB221}.Release|Any CPU.Build.0 = Release|Any CPU + {67485CAC-49F6-4D25-9EC9-017447454C3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67485CAC-49F6-4D25-9EC9-017447454C3B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67485CAC-49F6-4D25-9EC9-017447454C3B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67485CAC-49F6-4D25-9EC9-017447454C3B}.Release|Any CPU.Build.0 = Release|Any CPU + {5B859B2B-FE4D-4263-ADFA-6E89D4015AEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B859B2B-FE4D-4263-ADFA-6E89D4015AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B859B2B-FE4D-4263-ADFA-6E89D4015AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B859B2B-FE4D-4263-ADFA-6E89D4015AEE}.Release|Any CPU.Build.0 = Release|Any CPU + {4BCB8665-5BBB-487B-B463-13474598E59D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4BCB8665-5BBB-487B-B463-13474598E59D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4BCB8665-5BBB-487B-B463-13474598E59D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4BCB8665-5BBB-487B-B463-13474598E59D}.Release|Any CPU.Build.0 = Release|Any CPU + {3C479404-BFF4-4416-9D72-D1628C98A7F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3C479404-BFF4-4416-9D72-D1628C98A7F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3C479404-BFF4-4416-9D72-D1628C98A7F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3C479404-BFF4-4416-9D72-D1628C98A7F4}.Release|Any CPU.Build.0 = Release|Any CPU + {63C04643-D358-4346-9FC5-76177A1A85D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {63C04643-D358-4346-9FC5-76177A1A85D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {63C04643-D358-4346-9FC5-76177A1A85D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {63C04643-D358-4346-9FC5-76177A1A85D0}.Release|Any CPU.Build.0 = Release|Any CPU + {1E0D1E2E-4735-423A-8940-5A560F92B105}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1E0D1E2E-4735-423A-8940-5A560F92B105}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1E0D1E2E-4735-423A-8940-5A560F92B105}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1E0D1E2E-4735-423A-8940-5A560F92B105}.Release|Any CPU.Build.0 = Release|Any CPU + {B6C0B40B-16E4-497A-92A9-6589568DA54C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6C0B40B-16E4-497A-92A9-6589568DA54C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6C0B40B-16E4-497A-92A9-6589568DA54C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6C0B40B-16E4-497A-92A9-6589568DA54C}.Release|Any CPU.Build.0 = Release|Any CPU + {E9481EA8-3326-4D93-8D91-2E67354272F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9481EA8-3326-4D93-8D91-2E67354272F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9481EA8-3326-4D93-8D91-2E67354272F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9481EA8-3326-4D93-8D91-2E67354272F6}.Release|Any CPU.Build.0 = Release|Any CPU + {6432958B-E03E-45DE-823E-95105010EEEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6432958B-E03E-45DE-823E-95105010EEEC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6432958B-E03E-45DE-823E-95105010EEEC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6432958B-E03E-45DE-823E-95105010EEEC}.Release|Any CPU.Build.0 = Release|Any CPU + {5B82691D-3404-42A8-90CF-C1FD96367370}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5B82691D-3404-42A8-90CF-C1FD96367370}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5B82691D-3404-42A8-90CF-C1FD96367370}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5B82691D-3404-42A8-90CF-C1FD96367370}.Release|Any CPU.Build.0 = Release|Any CPU + {ADE5E4DC-8B14-46EC-8248-26C4DC3AD502}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ADE5E4DC-8B14-46EC-8248-26C4DC3AD502}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ADE5E4DC-8B14-46EC-8248-26C4DC3AD502}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ADE5E4DC-8B14-46EC-8248-26C4DC3AD502}.Release|Any CPU.Build.0 = Release|Any CPU + {BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1}.Release|Any CPU.Build.0 = Release|Any CPU + {A372B755-E329-4DFA-816D-DBE71A4FE679}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A372B755-E329-4DFA-816D-DBE71A4FE679}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A372B755-E329-4DFA-816D-DBE71A4FE679}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A372B755-E329-4DFA-816D-DBE71A4FE679}.Release|Any CPU.Build.0 = Release|Any CPU + {EB1954CC-3093-44A0-9A0D-2F39A51A8846}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EB1954CC-3093-44A0-9A0D-2F39A51A8846}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EB1954CC-3093-44A0-9A0D-2F39A51A8846}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EB1954CC-3093-44A0-9A0D-2F39A51A8846}.Release|Any CPU.Build.0 = Release|Any CPU + {CE1E9940-66A1-4E06-BFA2-25F3988E3BEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE1E9940-66A1-4E06-BFA2-25F3988E3BEB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE1E9940-66A1-4E06-BFA2-25F3988E3BEB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE1E9940-66A1-4E06-BFA2-25F3988E3BEB}.Release|Any CPU.Build.0 = Release|Any CPU + {404DAE0A-17CE-4049-B276-F1695B7114B3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {404DAE0A-17CE-4049-B276-F1695B7114B3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {404DAE0A-17CE-4049-B276-F1695B7114B3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {404DAE0A-17CE-4049-B276-F1695B7114B3}.Release|Any CPU.Build.0 = Release|Any CPU + {FB67BE8B-09DA-497F-868E-AC1729C7BF96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FB67BE8B-09DA-497F-868E-AC1729C7BF96}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FB67BE8B-09DA-497F-868E-AC1729C7BF96}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FB67BE8B-09DA-497F-868E-AC1729C7BF96}.Release|Any CPU.Build.0 = Release|Any CPU + {2F22755A-64F6-4281-8DA6-8F00871FC9EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2F22755A-64F6-4281-8DA6-8F00871FC9EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2F22755A-64F6-4281-8DA6-8F00871FC9EF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2F22755A-64F6-4281-8DA6-8F00871FC9EF}.Release|Any CPU.Build.0 = Release|Any CPU + {A7209996-5CB1-4D1F-AFC4-F50EE465FD98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A7209996-5CB1-4D1F-AFC4-F50EE465FD98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A7209996-5CB1-4D1F-AFC4-F50EE465FD98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A7209996-5CB1-4D1F-AFC4-F50EE465FD98}.Release|Any CPU.Build.0 = Release|Any CPU + {8DF3A058-7F98-4F2F-9601-32BE3312857C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DF3A058-7F98-4F2F-9601-32BE3312857C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DF3A058-7F98-4F2F-9601-32BE3312857C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DF3A058-7F98-4F2F-9601-32BE3312857C}.Release|Any CPU.Build.0 = Release|Any CPU + {82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82F6593B-3354-4246-B18E-B25A9DDEDBCC}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {DD750DA9-951E-4CF6-91A0-629B65FF6AD6} = {E7C08291-5975-4F77-BA54-06CAF8EC64EE} + {5087F9F3-D6AC-450E-A075-67643266BC3B} = {E7C08291-5975-4F77-BA54-06CAF8EC64EE} + {710A4F6C-FC52-4BD3-8163-62542C449B3D} = {8BB7FA2C-0E5C-4407-8773-BA9E970ACA11} + {1A72FFD5-3B27-4C30-88A2-1CB2B8539288} = {8BB7FA2C-0E5C-4407-8773-BA9E970ACA11} + {7FF6971A-0B77-4E38-ADA3-4A2C07561A6B} = {40E8A91B-A6A7-45EF-9D32-28E7B78109A2} + {E592A289-1AFE-47D8-88CB-89B99DCBC33F} = {40E8A91B-A6A7-45EF-9D32-28E7B78109A2} + {39F5BF2C-E541-498A-8305-6885DE7EB221} = {B697D39A-8F74-4F4F-8B11-118065033B21} + {67485CAC-49F6-4D25-9EC9-017447454C3B} = {B697D39A-8F74-4F4F-8B11-118065033B21} + {5B859B2B-FE4D-4263-ADFA-6E89D4015AEE} = {C6F14DE8-E27C-4689-B289-B7FEB2E6342C} + {4BCB8665-5BBB-487B-B463-13474598E59D} = {C6F14DE8-E27C-4689-B289-B7FEB2E6342C} + {3C479404-BFF4-4416-9D72-D1628C98A7F4} = {CB650B2B-DA2F-4FC3-AE86-2CC9BDAE5812} + {63C04643-D358-4346-9FC5-76177A1A85D0} = {CB650B2B-DA2F-4FC3-AE86-2CC9BDAE5812} + {1E0D1E2E-4735-423A-8940-5A560F92B105} = {A641F6D9-6528-4B22-8C47-635AD09EF1AF} + {B6C0B40B-16E4-497A-92A9-6589568DA54C} = {A641F6D9-6528-4B22-8C47-635AD09EF1AF} + {E9481EA8-3326-4D93-8D91-2E67354272F6} = {AC807DDB-75C0-4DCA-9568-26548D8360FE} + {6432958B-E03E-45DE-823E-95105010EEEC} = {AC807DDB-75C0-4DCA-9568-26548D8360FE} + {5B82691D-3404-42A8-90CF-C1FD96367370} = {D95CB972-5D41-49F9-BFEE-B48479AEEE85} + {ADE5E4DC-8B14-46EC-8248-26C4DC3AD502} = {D95CB972-5D41-49F9-BFEE-B48479AEEE85} + {BE0255E4-AE9A-4E0A-AB72-D83FED79E3E1} = {786D928F-5694-4460-9268-4B69864DB471} + {A372B755-E329-4DFA-816D-DBE71A4FE679} = {786D928F-5694-4460-9268-4B69864DB471} + {EB1954CC-3093-44A0-9A0D-2F39A51A8846} = {97C51EF3-0E68-425A-8CBF-99784C1178A3} + {CE1E9940-66A1-4E06-BFA2-25F3988E3BEB} = {97C51EF3-0E68-425A-8CBF-99784C1178A3} + {404DAE0A-17CE-4049-B276-F1695B7114B3} = {E9451070-74DE-47A3-978F-737711877891} + {FB67BE8B-09DA-497F-868E-AC1729C7BF96} = {E9451070-74DE-47A3-978F-737711877891} + {2F22755A-64F6-4281-8DA6-8F00871FC9EF} = {07E3D4B8-F361-4467-B27C-42B6D5427988} + {A7209996-5CB1-4D1F-AFC4-F50EE465FD98} = {07E3D4B8-F361-4467-B27C-42B6D5427988} + {8DF3A058-7F98-4F2F-9601-32BE3312857C} = {94CABFE2-1106-44CA-9722-54E3C2A77F21} + {82F6593B-3354-4246-B18E-B25A9DDEDBCC} = {94CABFE2-1106-44CA-9722-54E3C2A77F21} + EndGlobalSection +EndGlobal diff --git a/day01/day01.test/UnitTestProblem.cs b/day01/day01.test/UnitTestProblem.cs new file mode 100644 index 0000000..fa75d20 --- /dev/null +++ b/day01/day01.test/UnitTestProblem.cs @@ -0,0 +1,24 @@ +namespace day01.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("66487"); + //66487 + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("197301"); + //197301 + } +} \ No newline at end of file diff --git a/day01/day01.test/Usings.cs b/day01/day01.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day01/day01.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day01/day01.test/day01.test.csproj b/day01/day01.test/day01.test.csproj new file mode 100644 index 0000000..e558222 --- /dev/null +++ b/day01/day01.test/day01.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day01/day01.test/testdata.txt b/day01/day01.test/testdata.txt new file mode 100644 index 0000000..4f63175 --- /dev/null +++ b/day01/day01.test/testdata.txt @@ -0,0 +1,2259 @@ +4514 +8009 +6703 +1811 +4881 +3905 +3933 +9436 +4332 + +3059 +15715 +11597 +10625 +8486 + +4556 +10613 +4087 +11287 +12020 +1412 + +5320 +9757 +10646 +7373 +1197 +3486 +4359 + +16319 +22687 +5272 + +6167 +2478 +4950 +5513 +6113 +2739 +6805 +4488 +6555 +2752 + +2198 +2528 +3432 +2218 +3283 +1400 +1932 +3438 +1834 +1050 +4766 +5218 +3033 +3410 + +3362 +2773 +6782 +7416 +5388 +5419 +4628 +8877 + +2852 +7531 +6028 +8068 +3942 +9388 +8053 +6334 +6099 + +2086 +3097 +2914 +3087 +7500 +1718 +1482 +6198 +2057 +7098 +7464 + +4522 +4306 +1906 +6692 +1273 +3851 +6475 +1186 +6012 +2456 +2414 +5740 + +12352 +14613 +4339 +1259 +3363 + +5505 +5913 +6539 +4164 +10864 +8085 +4962 + +5427 +3232 +6945 +4536 +6549 +2299 +4450 +2130 +3757 + +8546 +3303 +9097 +2356 +3155 +1122 +6978 +3389 + +55471 + +3774 +7631 +2208 +11171 +5316 +1342 +5328 + +10879 +9002 +11257 +3581 +7878 +10258 + +2577 +1797 +5983 +11497 +3851 + +4420 +5333 +4281 +6978 +2230 +2658 +4337 +3238 +7724 +7813 +7326 + +1907 +1190 +6038 +6109 +4484 +5432 +6124 +7755 +8056 +7040 + +1782 +1645 +6918 +3525 +2147 +6923 +7008 +9695 + +3026 +5366 +2607 +6065 +3997 +2859 +2836 +5214 +5599 +3201 +3666 +1140 +4597 +5899 +4111 + +9757 +25752 +21486 + +16745 + +3571 +8001 +7104 +4253 +1833 +1393 +6105 +2036 +7697 +1066 +6702 + +2358 +4265 +1826 +5129 +1598 +1630 +3271 +2349 +5261 +3496 +4495 +6875 +3404 + +13904 +4223 +10247 +3708 + +8961 +13101 +6896 +11053 +6335 +11459 + +3948 +4739 +4888 +5918 +6229 +5056 +3039 +1030 +4181 +1801 +3716 +2410 +6056 +4574 + +5960 +8186 +3660 +3278 +3355 +1016 +6297 +6688 +7784 +4939 + +5957 +2549 +3045 +8425 +6900 +7677 +1393 +7579 +3975 +2936 + +3063 +5296 +3958 +5551 +3848 +3588 +3143 +1488 +3876 +7298 +3819 +2234 + +6478 +5440 +3993 +7207 +6141 +7936 +2209 +1456 +6417 +5250 +7690 + +5275 +11944 +2501 +4200 +11512 +13862 + +2941 +3403 +5950 +8661 +1801 +2843 +5444 +7960 +4143 +8379 + +6659 +5257 +2225 +5243 +4003 +2186 +5857 +3417 +1960 +3984 +4876 +1728 + +2105 +4101 +4754 +5537 +4265 +4678 +2571 +7662 +3726 +7258 +3696 + +16882 +7724 +3065 +5176 + +1721 +3594 +5892 +2019 +6036 +5556 +4327 +3334 +1035 +6942 +4931 +4084 +4900 + +10773 +10294 +7417 +1277 +9771 +8885 +6845 + +5226 + +9212 +2019 +2943 +11833 +13491 + +4581 +5217 +4441 +2337 +7312 +5529 +2051 +2388 +5011 +4581 +6601 + +3491 +3984 +4322 +5689 +2555 +1377 +5654 +6410 +4639 +5354 +3402 +4174 +2210 +3610 + +4130 +3186 +6120 +1344 +8012 +4477 +5849 +7346 +7418 +3218 +7778 + +10429 +14053 +10551 +8502 +1986 + +7470 +7166 +11309 +5186 + +8940 +10132 +19723 +15079 + +6791 +5344 +2331 +2805 +7742 + +2569 +7224 +5140 +3158 +5542 +2395 +2265 +2922 +5806 +6338 +6020 +3443 + +14741 +4547 +1076 +4543 +10298 + +2753 +4049 +6701 +2333 +2433 +4979 +5514 +3981 +6046 +2043 +6719 +3367 +6532 + +6962 +2222 +5696 +7206 +5679 +4041 +3633 +1043 +1466 +7205 +4116 + +10280 +17862 +17944 + +8670 +5423 +3849 +2444 +5010 +5564 +7740 +4000 +7893 +1137 + +10887 +16819 +7692 + +4397 +12537 +11166 +1875 +10936 + +6103 +6781 +5699 +1667 +6727 +2974 +5056 +3145 +6834 +4884 +6476 +2464 +2679 + +15428 +9750 +24018 + +2093 +3411 +4917 +2102 +3586 +5310 +2243 +4541 +4379 +5443 +6747 +3656 +1647 + +21030 + +2750 +5391 +1101 +5197 +2594 +5370 +4769 +5508 +3809 +1349 +5034 +1757 + +7071 +19487 +9131 + +9010 +6017 +11580 +10571 +3779 +3131 + +65413 + +1043 +9178 +8975 +1666 +8470 +2231 +8461 +8254 +2384 + +7499 +2336 +4819 +6472 +2467 +2726 +6179 +7218 +3422 +6760 + +21611 +4384 +15789 + +13272 +1281 +4032 +12189 +3263 +2092 + +18944 +22554 + +47475 + +11288 +12498 +5455 +8375 +15372 + +3279 +7755 +8865 +8027 +2351 +2164 +6867 +3546 + +2579 +2302 +5728 +1820 +5623 +4980 +1335 +6355 +5561 +6707 +3067 +3355 +5091 + +9430 +2156 +5053 +4895 +4751 +6864 +9518 +7626 +5000 + +7678 +4309 +2919 +8319 +7905 +1656 +6704 +7666 +5962 + +9153 +1759 +1344 +8101 +3844 +9197 +5987 + +19110 +9492 +13663 +5459 + +4112 +1162 +3983 +5407 +3246 +2129 +1940 +3455 +6758 +2091 +3272 +2441 +2344 + +3735 +3057 +6874 +4785 +6497 +5610 +2273 +6636 +2762 +4467 +2209 +7048 + +2947 +4945 +6535 +8432 +9028 +5316 +8208 +3277 + +3333 +6548 +4928 +1360 +1432 +5972 +4575 +4121 +6787 +6775 +5400 +5156 + +33497 + +4871 +5442 +6829 +2711 +7851 +5936 +4290 +3963 +1208 +6115 +3705 + +8801 +1239 +9742 +7859 +4868 +6162 +3990 +2116 + +3147 +5970 +1028 +2024 +1904 +5983 +1455 +1935 +6031 +4448 +4915 +3576 +5433 +4070 + +5581 +6684 +2338 +6998 +3365 +5190 +5551 +6858 +7120 +5143 +1078 +1636 + +1765 +8124 +3621 +5502 +3924 +7906 +6155 +5973 +6596 +8697 + +30733 +19954 + +1227 +7285 +8294 +6285 +2505 +7283 +3286 +4547 +5292 + +4767 +1039 +3045 +4567 +5790 +1224 +6805 +3689 +3941 +2191 +2509 +1020 +3261 + +1212 +2241 +2926 +5704 +4259 +2251 +2437 +3531 +3456 +5574 +4056 +6020 +2898 +5057 +1712 + +4532 +5547 +2323 +10119 +4161 +4809 +8820 +7200 + +7563 +2845 +1564 +7468 +3533 +8051 +6130 +7713 +6149 +4930 +5070 + +6145 +5654 +4039 +5029 +3369 +1330 +1739 +3554 +2637 +6281 +4225 +1559 +2998 +2723 + +46446 + +8785 +1461 +11831 +4977 +8704 + +5982 +7195 +2298 +6440 +4355 +7439 +6837 +1879 +5288 +3602 +4337 + +4272 +12891 +6936 +11964 +4734 +4828 + +1052 +5579 +5328 +1640 +5256 +1318 +1956 +6453 +6553 +5963 +2472 +2892 +3800 + +2898 +6365 +1775 +7440 +5182 +2004 +4704 +3905 +7436 +3530 +3931 + +4344 +4992 +3707 +2214 +3295 +4764 +2093 +1942 +6040 +2393 +2269 +4681 +6905 + +1051 +4442 +1254 +5438 +4390 +3861 +1951 +4766 +5814 +6431 +1181 +2224 +5036 +1744 + +3493 +5462 +1194 +3328 +3332 +6818 +5102 +6050 +1621 +3951 +5062 +1546 +4304 + +16366 +17043 +12935 +9439 + +8140 +1185 +8723 +3441 +1914 +6665 +3641 +1010 +5197 +5249 + +4795 +19775 +1502 +9970 + +14246 +11998 +12677 +5554 + +6733 +6173 +4063 +2994 +4069 +4907 +3381 +5065 +3066 + +54029 + +6782 +5629 +3154 +6967 +11148 +8169 +4309 + +4985 +2096 +4220 +6338 +2578 +6504 +4693 +2296 +6020 +1914 + +12080 +7332 + +4018 +5543 +1011 +5775 +2445 +4643 +2569 +4049 +3815 +7059 + +2221 +5799 +2865 +3002 +5123 +4587 +2616 +2486 +6544 +3510 +2072 +5583 +1202 + +20977 + +3908 +1548 +3974 +3030 +6060 +5685 +3743 +3660 +3953 +3097 +2451 +5463 +4462 +4164 +2274 + +3237 +4155 +3878 +7280 +6806 +6805 +7709 +5390 +4532 +3508 + +13465 +10177 +12174 +6555 +1931 +13866 + +1512 +3659 +5765 +2869 +6385 +4182 +5526 +2050 +4933 +5630 +3493 +5995 +1425 + +4335 +8051 +6448 +6574 +2379 +2517 +1438 +4618 +4844 +7733 +7984 + +1932 +2692 +1778 +2317 +2987 +2215 +4493 +5474 +1650 +4271 +4190 +1644 +5670 +4252 +5986 + +33522 +20921 + +5651 +4826 +1265 +10823 +3532 +1639 +2232 + +2727 +3843 +4970 +4981 +1783 +6192 +5106 + +12982 +10479 +16306 +13041 +13679 + +4778 +2726 +1427 +6216 +5710 +6500 +5576 +4088 +5634 +4158 +4877 +2578 +1648 +1329 + +5413 +7572 +2190 +7615 +3608 +7678 +3041 +3741 +6610 +6334 +1904 + +8421 +5311 +6287 +9371 +5937 +2671 +2911 + +18350 + +4656 +2569 +1655 +4154 +3594 +6325 +1829 +3426 +3380 +2482 +6305 +5656 + +5623 +17111 +20624 + +6359 +1958 +6109 +6287 +10371 +9097 +5626 +10542 + +12287 +7358 +12173 +15289 +1312 + +9307 +12837 +7109 +3993 +13645 +9731 + +4890 +5584 +5799 +5199 +1682 +3814 +2759 +2885 +4446 +4133 +6358 +5576 +5748 +1337 + +3017 +4273 +9032 +6029 +4492 +5168 +9962 +7038 + +11137 +12665 + +21501 +32719 + +4835 +4078 +7345 +7417 +5831 +9642 +7545 +5471 +2139 + +1508 +1647 +8202 +6437 +10415 +9614 +1551 +2297 + +10258 +17370 +7027 + +2258 +10853 +14703 +3899 + +13138 +18278 +11380 +11330 + +5362 +12051 +8062 +11651 +15184 + +7649 +9430 +5594 +4730 +4759 +5352 +11025 + +1001 +2798 +13426 +11713 +2081 +13053 + +4407 +1829 +3318 +1176 +3629 +5444 +3213 +6697 +5679 +6891 +3961 +6360 +1441 + +7428 +15180 +14117 +1510 +12963 + +3321 +3320 +2099 +2471 +3159 +1508 +1542 +4700 +4859 +1510 +5183 +2905 +1609 +5611 +3370 + +8936 +18333 +18055 +9369 + +7383 +6409 +1184 +6878 +7108 +2568 +5374 +7258 +5462 +7207 +2211 +6164 + +3675 +1118 +6252 +4861 +6231 +2161 +5556 +4454 +5419 +2729 +5963 +3351 +3544 + +2060 +7574 +6969 +2968 +4316 +5487 +2261 +1375 +1796 +7321 + +2708 +10030 +4543 +2573 +4708 +1342 +10369 +10452 + +25141 +19156 +10265 + +2291 +3072 +6329 +6608 +6437 +2654 +5965 +1873 +6091 +6377 +3098 +3708 +3983 + +3047 +8364 +4720 +1678 +1720 +8052 +6597 +2818 +7694 +7541 + +7453 +7491 +5792 +4864 +1486 +2471 +7657 +5603 +3222 +5398 +4459 + +3768 +3173 +1690 +2872 +4294 +5843 +5425 +5110 +1988 +1660 +6431 +3632 +4896 +2094 + +2685 +6829 +6302 +1294 +5920 +6517 +6218 +4705 +4098 +6474 +2341 +1907 + +5531 +23363 +22143 + +17140 +13864 +7305 +13004 + +1924 +2874 +1231 +4930 +2131 +3807 +5767 +5536 +1716 +1084 +2675 +3694 +3267 +2248 +2655 + +9692 +2588 +6897 +10903 +2978 + +3149 +8346 +3871 +1283 +3229 +7102 +6218 +8464 +6478 +6861 + +5967 +3879 +2451 +3677 +4833 +3397 +5966 +2456 +3384 +6944 +5076 + +14894 +18504 +14068 +1686 + +3125 +1927 +1998 +5447 +1736 +4314 +3658 +3604 +3974 +2081 +5045 +3374 +3999 +2334 +1141 + +7064 +13794 + +9500 +2963 +2683 +7601 +5231 +1168 +6598 +8435 +4459 + +1551 +3535 +5559 +3981 +2449 +5891 +1862 +4689 +6438 +2998 +5800 +3080 +3931 +5084 + +2977 +4986 +1241 +2931 +5795 +2783 +2643 +1917 +1246 +3664 +1974 +1619 +5715 +5610 +3614 + +29617 +32230 + +6879 +11068 +6443 +7504 +8107 +13469 + +10186 +22380 + +4308 +5637 +4183 +5385 +4857 +2530 +5744 +5698 +5974 +1331 +1545 +1817 +4727 + +15946 +21142 +16286 + +1355 +4589 +2441 +4682 +4249 +7641 +6701 +7947 +6846 +3037 +3281 + +2827 +4389 +15815 +17784 + +5460 +5000 +18466 + +2896 +7920 +1294 +3749 +3284 +11674 +10546 + +9645 +3616 +5426 +5033 +6267 +5149 +2317 +7252 + +11261 +7599 +7070 +11079 +12583 +9632 + +5003 +3675 +2638 +4788 +6358 +5844 +3350 +5636 +1390 +2913 +2232 +5648 +5939 +4955 + +12306 +24639 +21554 + +4949 +7026 +4490 +2871 +5707 +1733 +6263 +3539 +1017 +3931 +6667 +7220 + +50107 + +1353 +18516 +16760 +17546 + +17547 +18508 +12691 +16655 + +10956 +2619 +3158 +5111 +4375 +6522 +8374 + +3719 +2133 +4951 +6984 +2470 +6827 +5425 +2317 +1196 +1167 +1082 +5110 + +1780 +4083 +2628 +1244 +2630 +1111 +1212 +4620 +1361 +4214 +5617 +1347 +2713 +5083 +2211 + +6596 +5657 +3296 +2932 +1807 +8779 +7052 +3786 +4635 +1777 + +1354 +5299 +6443 +5523 +4715 +5121 +7567 +6337 +5534 +1844 +4533 + +23322 +1210 +3150 + +2484 +1722 +8751 +3583 +3184 +5899 +1472 +2242 +2055 +8239 + +6447 +4108 +6164 +5512 +3711 +6093 +3813 +1251 +6188 +1785 +4931 +3077 + +9885 +9867 +5861 +2405 +6334 +10881 +3816 + +7650 +4178 +8336 +8110 +1777 +7897 +9552 +6168 + +3208 +5307 +4567 +1317 +4974 +5175 +3512 +3402 +4728 +5527 +5545 +3284 +5596 +4062 +1904 + +6032 +4154 +3490 +12546 +5649 +5270 + +6961 +4013 +4916 +4179 +1211 +7349 +4890 +1517 +4413 +1651 +2315 +5808 + +7126 +16312 +18704 +6831 + +2261 +18391 +6281 +8852 + +1946 +6964 +8157 +2974 +5601 +1525 +3589 +2946 + +5734 +4359 +5519 +1372 +4662 +3645 +5657 +5662 +2586 +3218 + +3863 +4000 +1419 +9581 +7539 +7915 +2498 +1755 +7816 + +4417 +8141 +2738 +2439 +6030 +8163 +7689 +2724 +1714 +4775 + +25107 +23575 + +2326 +4714 +3260 +2151 +2626 +3462 +3721 +2064 +4631 +5006 +4407 +3312 +6082 +5398 +2887 + +15426 +8430 +8716 +13178 +9542 + +14059 +12861 +2877 + +29214 + +3226 +2480 +4432 +4062 +6295 +6194 +6685 +6480 +5192 +4150 + +2195 +3530 +8899 +6012 +1369 +1331 +3203 +3697 +6926 + +10843 +8715 +8009 +6756 +4204 +12089 + +2746 +3205 +5651 +3786 +6044 +6925 +6238 +5885 +3987 +4287 +1110 +1508 +6693 + +20460 +11678 + +2887 +2535 +2228 +7308 +6658 +3702 +4383 +4508 +6215 +3048 +2140 + +25977 + +19958 +20751 +8435 + +8100 +2237 +2012 +5688 +6781 +6579 +7230 +2736 +8174 +3292 + +4153 +1026 +2393 +1798 +4098 +5538 +5024 +5596 +5731 +4619 +5547 +4523 +1765 +1443 +1659 + +28275 +14784 + +24558 +17590 +1011 + +1137 +1609 +3378 +8204 +1517 +5949 +1055 +6075 +1424 +2625 + +1374 +2356 +4734 +5102 +5200 +6172 +4473 +4267 +2878 +1711 +1228 +3968 +2210 + +1584 +7971 +7179 +4611 +1451 +1960 +5043 +5751 +3128 +6834 + +4158 +5288 +12009 +2525 +4308 +6756 + +15397 +14866 +14231 + +2921 +5355 +4326 +3965 +6581 +1724 +6805 +4925 +6913 +5527 + +6849 +3614 +6330 +3612 +5259 +6735 +1603 +3153 +5160 +5526 +5990 +2125 + +3994 +7956 +1295 +17255 + +48885 + +8156 +10864 +20472 + +12590 +12826 +3397 +6956 +10270 +11191 + +6437 +5402 +5892 +13043 +7154 + +3074 +5746 +6941 +4546 +6483 +6929 +7339 +3236 +2521 +1728 +5400 + +5981 +2368 +2910 +4789 +4622 +1146 +2793 +5396 +5501 +4040 +4427 +5061 +4944 +6396 + +3890 +8736 +7073 +2115 +2762 +7470 +9355 +1754 + +10134 +24611 +20758 + +3021 +4624 +12109 +10211 + +3813 +2422 +4148 +1626 +1124 +6512 +5130 +4874 +5287 +5100 +1147 + +6020 +1121 +6018 +9226 +2792 +3706 + +8027 +14155 +14228 +11648 +14866 + +8839 +15560 +10935 +2677 +2764 + +6261 +13041 +5795 +11615 +9834 +7578 + +5560 +1044 +5120 +4165 +4273 +2333 +2606 +4919 +2166 +2723 +2711 +4169 +1192 +3290 +3375 + +9912 +13241 +10389 +6685 +4808 +1306 + +53747 + +13478 +10567 + +14438 +13430 +18691 +9087 + +3117 +1338 +5317 +3267 +2837 +4002 +4449 +3199 +2409 +2922 +2136 +1663 +4246 +1331 +3420 \ No newline at end of file diff --git a/day01/day01/.vscode/launch.json b/day01/day01/.vscode/launch.json new file mode 100644 index 0000000..6582be2 --- /dev/null +++ b/day01/day01/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/bin/Debug/net6.0/day01.dll", + "args": [], + "cwd": "${workspaceFolder}", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/day01/day01/.vscode/tasks.json b/day01/day01/.vscode/tasks.json new file mode 100644 index 0000000..b791f52 --- /dev/null +++ b/day01/day01/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/day01.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/day01.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/day01.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/day01/day01/Elf.cs b/day01/day01/Elf.cs new file mode 100644 index 0000000..b655aae --- /dev/null +++ b/day01/day01/Elf.cs @@ -0,0 +1,7 @@ +namespace day01; + +public class Elf +{ + public int Index { get; set; } + public int Calories { get; set; } +} diff --git a/day01/day01/Problem.cs b/day01/day01/Problem.cs new file mode 100644 index 0000000..37bf917 --- /dev/null +++ b/day01/day01/Problem.cs @@ -0,0 +1,73 @@ +namespace day01; +public class Problem +{ + List lst = new List(); + + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + int maxValue = 0; + int currentValue = 0; + int idx = -1; + int maxIdx = -1; + int elfno = 1; + int maxelfno = 0; + foreach (var line in lines) + { + idx++; + if (string.IsNullOrEmpty(line)) + { + lst.Add(new Elf + { + Index = idx, + Calories = currentValue + }); + // System.Console.WriteLine($"elf: {elfno} calories: {currentValue} at line {idx}"); + if (currentValue > maxValue) + { + maxIdx = idx; + maxValue = currentValue; + maxelfno = elfno; + } + currentValue = 0; + elfno++; + } + else + { + currentValue += int.Parse(line); + } + } + if (currentValue > 0) + { + lst.Add(new Elf + { + Index = idx, + Calories = currentValue + }); + } + + // System.Console.WriteLine($"max elf {maxelfno} calories: {maxValue} at line {maxIdx}"); + Result1 = maxValue.ToString(); + } + + public void ResolvePart2(string arg) + { + ResolvePart1(arg); + + var topThree = lst + .OrderByDescending(x => x.Calories) + .Take(3); + // foreach (var tt in topThree) + // { + // System.Console.WriteLine($"tt {tt.Index} v: {tt.Calories}"); + // } + var ttTotal = topThree.Sum(x => x.Calories); + // System.Console.WriteLine($"tt total: {ttTotal}"); + Result2 = ttTotal.ToString(); + } + +} \ No newline at end of file diff --git a/day01/day01/Program.cs b/day01/day01/Program.cs new file mode 100644 index 0000000..4217052 --- /dev/null +++ b/day01/day01/Program.cs @@ -0,0 +1,13 @@ +namespace day01; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + var problem = new Problem(); + problem.ResolvePart2(inputFile);//solves also part 1 + + System.Console.WriteLine($"Result1: Total calories of that elf: {problem.Result1}"); + System.Console.WriteLine($"Result2: Total calories of those elfs: {problem.Result2}"); + } +} diff --git a/day01/day01/day01.csproj b/day01/day01/day01.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day01/day01/day01.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day01/day01/input.txt b/day01/day01/input.txt new file mode 100644 index 0000000..4f63175 --- /dev/null +++ b/day01/day01/input.txt @@ -0,0 +1,2259 @@ +4514 +8009 +6703 +1811 +4881 +3905 +3933 +9436 +4332 + +3059 +15715 +11597 +10625 +8486 + +4556 +10613 +4087 +11287 +12020 +1412 + +5320 +9757 +10646 +7373 +1197 +3486 +4359 + +16319 +22687 +5272 + +6167 +2478 +4950 +5513 +6113 +2739 +6805 +4488 +6555 +2752 + +2198 +2528 +3432 +2218 +3283 +1400 +1932 +3438 +1834 +1050 +4766 +5218 +3033 +3410 + +3362 +2773 +6782 +7416 +5388 +5419 +4628 +8877 + +2852 +7531 +6028 +8068 +3942 +9388 +8053 +6334 +6099 + +2086 +3097 +2914 +3087 +7500 +1718 +1482 +6198 +2057 +7098 +7464 + +4522 +4306 +1906 +6692 +1273 +3851 +6475 +1186 +6012 +2456 +2414 +5740 + +12352 +14613 +4339 +1259 +3363 + +5505 +5913 +6539 +4164 +10864 +8085 +4962 + +5427 +3232 +6945 +4536 +6549 +2299 +4450 +2130 +3757 + +8546 +3303 +9097 +2356 +3155 +1122 +6978 +3389 + +55471 + +3774 +7631 +2208 +11171 +5316 +1342 +5328 + +10879 +9002 +11257 +3581 +7878 +10258 + +2577 +1797 +5983 +11497 +3851 + +4420 +5333 +4281 +6978 +2230 +2658 +4337 +3238 +7724 +7813 +7326 + +1907 +1190 +6038 +6109 +4484 +5432 +6124 +7755 +8056 +7040 + +1782 +1645 +6918 +3525 +2147 +6923 +7008 +9695 + +3026 +5366 +2607 +6065 +3997 +2859 +2836 +5214 +5599 +3201 +3666 +1140 +4597 +5899 +4111 + +9757 +25752 +21486 + +16745 + +3571 +8001 +7104 +4253 +1833 +1393 +6105 +2036 +7697 +1066 +6702 + +2358 +4265 +1826 +5129 +1598 +1630 +3271 +2349 +5261 +3496 +4495 +6875 +3404 + +13904 +4223 +10247 +3708 + +8961 +13101 +6896 +11053 +6335 +11459 + +3948 +4739 +4888 +5918 +6229 +5056 +3039 +1030 +4181 +1801 +3716 +2410 +6056 +4574 + +5960 +8186 +3660 +3278 +3355 +1016 +6297 +6688 +7784 +4939 + +5957 +2549 +3045 +8425 +6900 +7677 +1393 +7579 +3975 +2936 + +3063 +5296 +3958 +5551 +3848 +3588 +3143 +1488 +3876 +7298 +3819 +2234 + +6478 +5440 +3993 +7207 +6141 +7936 +2209 +1456 +6417 +5250 +7690 + +5275 +11944 +2501 +4200 +11512 +13862 + +2941 +3403 +5950 +8661 +1801 +2843 +5444 +7960 +4143 +8379 + +6659 +5257 +2225 +5243 +4003 +2186 +5857 +3417 +1960 +3984 +4876 +1728 + +2105 +4101 +4754 +5537 +4265 +4678 +2571 +7662 +3726 +7258 +3696 + +16882 +7724 +3065 +5176 + +1721 +3594 +5892 +2019 +6036 +5556 +4327 +3334 +1035 +6942 +4931 +4084 +4900 + +10773 +10294 +7417 +1277 +9771 +8885 +6845 + +5226 + +9212 +2019 +2943 +11833 +13491 + +4581 +5217 +4441 +2337 +7312 +5529 +2051 +2388 +5011 +4581 +6601 + +3491 +3984 +4322 +5689 +2555 +1377 +5654 +6410 +4639 +5354 +3402 +4174 +2210 +3610 + +4130 +3186 +6120 +1344 +8012 +4477 +5849 +7346 +7418 +3218 +7778 + +10429 +14053 +10551 +8502 +1986 + +7470 +7166 +11309 +5186 + +8940 +10132 +19723 +15079 + +6791 +5344 +2331 +2805 +7742 + +2569 +7224 +5140 +3158 +5542 +2395 +2265 +2922 +5806 +6338 +6020 +3443 + +14741 +4547 +1076 +4543 +10298 + +2753 +4049 +6701 +2333 +2433 +4979 +5514 +3981 +6046 +2043 +6719 +3367 +6532 + +6962 +2222 +5696 +7206 +5679 +4041 +3633 +1043 +1466 +7205 +4116 + +10280 +17862 +17944 + +8670 +5423 +3849 +2444 +5010 +5564 +7740 +4000 +7893 +1137 + +10887 +16819 +7692 + +4397 +12537 +11166 +1875 +10936 + +6103 +6781 +5699 +1667 +6727 +2974 +5056 +3145 +6834 +4884 +6476 +2464 +2679 + +15428 +9750 +24018 + +2093 +3411 +4917 +2102 +3586 +5310 +2243 +4541 +4379 +5443 +6747 +3656 +1647 + +21030 + +2750 +5391 +1101 +5197 +2594 +5370 +4769 +5508 +3809 +1349 +5034 +1757 + +7071 +19487 +9131 + +9010 +6017 +11580 +10571 +3779 +3131 + +65413 + +1043 +9178 +8975 +1666 +8470 +2231 +8461 +8254 +2384 + +7499 +2336 +4819 +6472 +2467 +2726 +6179 +7218 +3422 +6760 + +21611 +4384 +15789 + +13272 +1281 +4032 +12189 +3263 +2092 + +18944 +22554 + +47475 + +11288 +12498 +5455 +8375 +15372 + +3279 +7755 +8865 +8027 +2351 +2164 +6867 +3546 + +2579 +2302 +5728 +1820 +5623 +4980 +1335 +6355 +5561 +6707 +3067 +3355 +5091 + +9430 +2156 +5053 +4895 +4751 +6864 +9518 +7626 +5000 + +7678 +4309 +2919 +8319 +7905 +1656 +6704 +7666 +5962 + +9153 +1759 +1344 +8101 +3844 +9197 +5987 + +19110 +9492 +13663 +5459 + +4112 +1162 +3983 +5407 +3246 +2129 +1940 +3455 +6758 +2091 +3272 +2441 +2344 + +3735 +3057 +6874 +4785 +6497 +5610 +2273 +6636 +2762 +4467 +2209 +7048 + +2947 +4945 +6535 +8432 +9028 +5316 +8208 +3277 + +3333 +6548 +4928 +1360 +1432 +5972 +4575 +4121 +6787 +6775 +5400 +5156 + +33497 + +4871 +5442 +6829 +2711 +7851 +5936 +4290 +3963 +1208 +6115 +3705 + +8801 +1239 +9742 +7859 +4868 +6162 +3990 +2116 + +3147 +5970 +1028 +2024 +1904 +5983 +1455 +1935 +6031 +4448 +4915 +3576 +5433 +4070 + +5581 +6684 +2338 +6998 +3365 +5190 +5551 +6858 +7120 +5143 +1078 +1636 + +1765 +8124 +3621 +5502 +3924 +7906 +6155 +5973 +6596 +8697 + +30733 +19954 + +1227 +7285 +8294 +6285 +2505 +7283 +3286 +4547 +5292 + +4767 +1039 +3045 +4567 +5790 +1224 +6805 +3689 +3941 +2191 +2509 +1020 +3261 + +1212 +2241 +2926 +5704 +4259 +2251 +2437 +3531 +3456 +5574 +4056 +6020 +2898 +5057 +1712 + +4532 +5547 +2323 +10119 +4161 +4809 +8820 +7200 + +7563 +2845 +1564 +7468 +3533 +8051 +6130 +7713 +6149 +4930 +5070 + +6145 +5654 +4039 +5029 +3369 +1330 +1739 +3554 +2637 +6281 +4225 +1559 +2998 +2723 + +46446 + +8785 +1461 +11831 +4977 +8704 + +5982 +7195 +2298 +6440 +4355 +7439 +6837 +1879 +5288 +3602 +4337 + +4272 +12891 +6936 +11964 +4734 +4828 + +1052 +5579 +5328 +1640 +5256 +1318 +1956 +6453 +6553 +5963 +2472 +2892 +3800 + +2898 +6365 +1775 +7440 +5182 +2004 +4704 +3905 +7436 +3530 +3931 + +4344 +4992 +3707 +2214 +3295 +4764 +2093 +1942 +6040 +2393 +2269 +4681 +6905 + +1051 +4442 +1254 +5438 +4390 +3861 +1951 +4766 +5814 +6431 +1181 +2224 +5036 +1744 + +3493 +5462 +1194 +3328 +3332 +6818 +5102 +6050 +1621 +3951 +5062 +1546 +4304 + +16366 +17043 +12935 +9439 + +8140 +1185 +8723 +3441 +1914 +6665 +3641 +1010 +5197 +5249 + +4795 +19775 +1502 +9970 + +14246 +11998 +12677 +5554 + +6733 +6173 +4063 +2994 +4069 +4907 +3381 +5065 +3066 + +54029 + +6782 +5629 +3154 +6967 +11148 +8169 +4309 + +4985 +2096 +4220 +6338 +2578 +6504 +4693 +2296 +6020 +1914 + +12080 +7332 + +4018 +5543 +1011 +5775 +2445 +4643 +2569 +4049 +3815 +7059 + +2221 +5799 +2865 +3002 +5123 +4587 +2616 +2486 +6544 +3510 +2072 +5583 +1202 + +20977 + +3908 +1548 +3974 +3030 +6060 +5685 +3743 +3660 +3953 +3097 +2451 +5463 +4462 +4164 +2274 + +3237 +4155 +3878 +7280 +6806 +6805 +7709 +5390 +4532 +3508 + +13465 +10177 +12174 +6555 +1931 +13866 + +1512 +3659 +5765 +2869 +6385 +4182 +5526 +2050 +4933 +5630 +3493 +5995 +1425 + +4335 +8051 +6448 +6574 +2379 +2517 +1438 +4618 +4844 +7733 +7984 + +1932 +2692 +1778 +2317 +2987 +2215 +4493 +5474 +1650 +4271 +4190 +1644 +5670 +4252 +5986 + +33522 +20921 + +5651 +4826 +1265 +10823 +3532 +1639 +2232 + +2727 +3843 +4970 +4981 +1783 +6192 +5106 + +12982 +10479 +16306 +13041 +13679 + +4778 +2726 +1427 +6216 +5710 +6500 +5576 +4088 +5634 +4158 +4877 +2578 +1648 +1329 + +5413 +7572 +2190 +7615 +3608 +7678 +3041 +3741 +6610 +6334 +1904 + +8421 +5311 +6287 +9371 +5937 +2671 +2911 + +18350 + +4656 +2569 +1655 +4154 +3594 +6325 +1829 +3426 +3380 +2482 +6305 +5656 + +5623 +17111 +20624 + +6359 +1958 +6109 +6287 +10371 +9097 +5626 +10542 + +12287 +7358 +12173 +15289 +1312 + +9307 +12837 +7109 +3993 +13645 +9731 + +4890 +5584 +5799 +5199 +1682 +3814 +2759 +2885 +4446 +4133 +6358 +5576 +5748 +1337 + +3017 +4273 +9032 +6029 +4492 +5168 +9962 +7038 + +11137 +12665 + +21501 +32719 + +4835 +4078 +7345 +7417 +5831 +9642 +7545 +5471 +2139 + +1508 +1647 +8202 +6437 +10415 +9614 +1551 +2297 + +10258 +17370 +7027 + +2258 +10853 +14703 +3899 + +13138 +18278 +11380 +11330 + +5362 +12051 +8062 +11651 +15184 + +7649 +9430 +5594 +4730 +4759 +5352 +11025 + +1001 +2798 +13426 +11713 +2081 +13053 + +4407 +1829 +3318 +1176 +3629 +5444 +3213 +6697 +5679 +6891 +3961 +6360 +1441 + +7428 +15180 +14117 +1510 +12963 + +3321 +3320 +2099 +2471 +3159 +1508 +1542 +4700 +4859 +1510 +5183 +2905 +1609 +5611 +3370 + +8936 +18333 +18055 +9369 + +7383 +6409 +1184 +6878 +7108 +2568 +5374 +7258 +5462 +7207 +2211 +6164 + +3675 +1118 +6252 +4861 +6231 +2161 +5556 +4454 +5419 +2729 +5963 +3351 +3544 + +2060 +7574 +6969 +2968 +4316 +5487 +2261 +1375 +1796 +7321 + +2708 +10030 +4543 +2573 +4708 +1342 +10369 +10452 + +25141 +19156 +10265 + +2291 +3072 +6329 +6608 +6437 +2654 +5965 +1873 +6091 +6377 +3098 +3708 +3983 + +3047 +8364 +4720 +1678 +1720 +8052 +6597 +2818 +7694 +7541 + +7453 +7491 +5792 +4864 +1486 +2471 +7657 +5603 +3222 +5398 +4459 + +3768 +3173 +1690 +2872 +4294 +5843 +5425 +5110 +1988 +1660 +6431 +3632 +4896 +2094 + +2685 +6829 +6302 +1294 +5920 +6517 +6218 +4705 +4098 +6474 +2341 +1907 + +5531 +23363 +22143 + +17140 +13864 +7305 +13004 + +1924 +2874 +1231 +4930 +2131 +3807 +5767 +5536 +1716 +1084 +2675 +3694 +3267 +2248 +2655 + +9692 +2588 +6897 +10903 +2978 + +3149 +8346 +3871 +1283 +3229 +7102 +6218 +8464 +6478 +6861 + +5967 +3879 +2451 +3677 +4833 +3397 +5966 +2456 +3384 +6944 +5076 + +14894 +18504 +14068 +1686 + +3125 +1927 +1998 +5447 +1736 +4314 +3658 +3604 +3974 +2081 +5045 +3374 +3999 +2334 +1141 + +7064 +13794 + +9500 +2963 +2683 +7601 +5231 +1168 +6598 +8435 +4459 + +1551 +3535 +5559 +3981 +2449 +5891 +1862 +4689 +6438 +2998 +5800 +3080 +3931 +5084 + +2977 +4986 +1241 +2931 +5795 +2783 +2643 +1917 +1246 +3664 +1974 +1619 +5715 +5610 +3614 + +29617 +32230 + +6879 +11068 +6443 +7504 +8107 +13469 + +10186 +22380 + +4308 +5637 +4183 +5385 +4857 +2530 +5744 +5698 +5974 +1331 +1545 +1817 +4727 + +15946 +21142 +16286 + +1355 +4589 +2441 +4682 +4249 +7641 +6701 +7947 +6846 +3037 +3281 + +2827 +4389 +15815 +17784 + +5460 +5000 +18466 + +2896 +7920 +1294 +3749 +3284 +11674 +10546 + +9645 +3616 +5426 +5033 +6267 +5149 +2317 +7252 + +11261 +7599 +7070 +11079 +12583 +9632 + +5003 +3675 +2638 +4788 +6358 +5844 +3350 +5636 +1390 +2913 +2232 +5648 +5939 +4955 + +12306 +24639 +21554 + +4949 +7026 +4490 +2871 +5707 +1733 +6263 +3539 +1017 +3931 +6667 +7220 + +50107 + +1353 +18516 +16760 +17546 + +17547 +18508 +12691 +16655 + +10956 +2619 +3158 +5111 +4375 +6522 +8374 + +3719 +2133 +4951 +6984 +2470 +6827 +5425 +2317 +1196 +1167 +1082 +5110 + +1780 +4083 +2628 +1244 +2630 +1111 +1212 +4620 +1361 +4214 +5617 +1347 +2713 +5083 +2211 + +6596 +5657 +3296 +2932 +1807 +8779 +7052 +3786 +4635 +1777 + +1354 +5299 +6443 +5523 +4715 +5121 +7567 +6337 +5534 +1844 +4533 + +23322 +1210 +3150 + +2484 +1722 +8751 +3583 +3184 +5899 +1472 +2242 +2055 +8239 + +6447 +4108 +6164 +5512 +3711 +6093 +3813 +1251 +6188 +1785 +4931 +3077 + +9885 +9867 +5861 +2405 +6334 +10881 +3816 + +7650 +4178 +8336 +8110 +1777 +7897 +9552 +6168 + +3208 +5307 +4567 +1317 +4974 +5175 +3512 +3402 +4728 +5527 +5545 +3284 +5596 +4062 +1904 + +6032 +4154 +3490 +12546 +5649 +5270 + +6961 +4013 +4916 +4179 +1211 +7349 +4890 +1517 +4413 +1651 +2315 +5808 + +7126 +16312 +18704 +6831 + +2261 +18391 +6281 +8852 + +1946 +6964 +8157 +2974 +5601 +1525 +3589 +2946 + +5734 +4359 +5519 +1372 +4662 +3645 +5657 +5662 +2586 +3218 + +3863 +4000 +1419 +9581 +7539 +7915 +2498 +1755 +7816 + +4417 +8141 +2738 +2439 +6030 +8163 +7689 +2724 +1714 +4775 + +25107 +23575 + +2326 +4714 +3260 +2151 +2626 +3462 +3721 +2064 +4631 +5006 +4407 +3312 +6082 +5398 +2887 + +15426 +8430 +8716 +13178 +9542 + +14059 +12861 +2877 + +29214 + +3226 +2480 +4432 +4062 +6295 +6194 +6685 +6480 +5192 +4150 + +2195 +3530 +8899 +6012 +1369 +1331 +3203 +3697 +6926 + +10843 +8715 +8009 +6756 +4204 +12089 + +2746 +3205 +5651 +3786 +6044 +6925 +6238 +5885 +3987 +4287 +1110 +1508 +6693 + +20460 +11678 + +2887 +2535 +2228 +7308 +6658 +3702 +4383 +4508 +6215 +3048 +2140 + +25977 + +19958 +20751 +8435 + +8100 +2237 +2012 +5688 +6781 +6579 +7230 +2736 +8174 +3292 + +4153 +1026 +2393 +1798 +4098 +5538 +5024 +5596 +5731 +4619 +5547 +4523 +1765 +1443 +1659 + +28275 +14784 + +24558 +17590 +1011 + +1137 +1609 +3378 +8204 +1517 +5949 +1055 +6075 +1424 +2625 + +1374 +2356 +4734 +5102 +5200 +6172 +4473 +4267 +2878 +1711 +1228 +3968 +2210 + +1584 +7971 +7179 +4611 +1451 +1960 +5043 +5751 +3128 +6834 + +4158 +5288 +12009 +2525 +4308 +6756 + +15397 +14866 +14231 + +2921 +5355 +4326 +3965 +6581 +1724 +6805 +4925 +6913 +5527 + +6849 +3614 +6330 +3612 +5259 +6735 +1603 +3153 +5160 +5526 +5990 +2125 + +3994 +7956 +1295 +17255 + +48885 + +8156 +10864 +20472 + +12590 +12826 +3397 +6956 +10270 +11191 + +6437 +5402 +5892 +13043 +7154 + +3074 +5746 +6941 +4546 +6483 +6929 +7339 +3236 +2521 +1728 +5400 + +5981 +2368 +2910 +4789 +4622 +1146 +2793 +5396 +5501 +4040 +4427 +5061 +4944 +6396 + +3890 +8736 +7073 +2115 +2762 +7470 +9355 +1754 + +10134 +24611 +20758 + +3021 +4624 +12109 +10211 + +3813 +2422 +4148 +1626 +1124 +6512 +5130 +4874 +5287 +5100 +1147 + +6020 +1121 +6018 +9226 +2792 +3706 + +8027 +14155 +14228 +11648 +14866 + +8839 +15560 +10935 +2677 +2764 + +6261 +13041 +5795 +11615 +9834 +7578 + +5560 +1044 +5120 +4165 +4273 +2333 +2606 +4919 +2166 +2723 +2711 +4169 +1192 +3290 +3375 + +9912 +13241 +10389 +6685 +4808 +1306 + +53747 + +13478 +10567 + +14438 +13430 +18691 +9087 + +3117 +1338 +5317 +3267 +2837 +4002 +4449 +3199 +2409 +2922 +2136 +1663 +4246 +1331 +3420 \ No newline at end of file diff --git a/day01/problem.md b/day01/problem.md new file mode 100644 index 0000000..4ad8754 --- /dev/null +++ b/day01/problem.md @@ -0,0 +1,58 @@ +--- Day 1: Calorie Counting --- +Santa's reindeer typically eat regular reindeer food, but they need a lot of magical energy to deliver presents on Christmas. For that, their favorite snack is a special type of star fruit that only grows deep in the jungle. The Elves have brought you on their annual expedition to the grove where the fruit grows. + +To supply enough magical energy, the expedition needs to retrieve a minimum of fifty stars by December 25th. Although the Elves assure you that the grove has plenty of fruit, you decide to grab any fruit you see along the way, just in case. + +Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck! + +The jungle must be too overgrown and difficult to navigate in vehicles or access from the air; the Elves' expedition traditionally goes on foot. As your boats approach land, the Elves begin taking inventory of their supplies. One important consideration is food - in particular, the number of Calories each Elf is carrying (your puzzle input). + +The Elves take turns writing down the number of Calories contained by the various meals, snacks, rations, etc. that they've brought with them, one item per line. Each Elf separates their own inventory from the previous Elf's inventory (if any) by a blank line. + +For example, suppose the Elves finish writing their items' Calories and end up with the following list: + +1000 +2000 +3000 + +4000 + +5000 +6000 + +7000 +8000 +9000 + +10000 +This list represents the Calories of the food carried by five Elves: + +The first Elf is carrying food with 1000, 2000, and 3000 Calories, a total of 6000 Calories. +The second Elf is carrying one food item with 4000 Calories. +The third Elf is carrying food with 5000 and 6000 Calories, a total of 11000 Calories. +The fourth Elf is carrying food with 7000, 8000, and 9000 Calories, a total of 24000 Calories. +The fifth Elf is carrying one food item with 10000 Calories. +In case the Elves get hungry and need extra snacks, they need to know which Elf to ask: they'd like to know how many Calories are being carried by the Elf carrying the most Calories. In the example above, this is 24000 (carried by the fourth Elf). + +Find the Elf carrying the most Calories. How many total Calories is that Elf carrying? + +Your puzzle answer was 66487. + +--- Part Two --- +By the time you calculate the answer to the Elves' question, they've already realized that the Elf carrying the most Calories of food might eventually run out of snacks. + +To avoid this unacceptable situation, the Elves would instead like to know the total Calories carried by the top three Elves carrying the most Calories. That way, even if one of those Elves runs out of snacks, they still have two backups. + +In the example above, the top three Elves are the fourth Elf (with 24000 Calories), then the third Elf (with 11000 Calories), then the fifth Elf (with 10000 Calories). The sum of the Calories carried by these three elves is 45000. + +Find the top three Elves carrying the most Calories. How many Calories are those Elves carrying in total? + +Your puzzle answer was 197301. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day02/day02.test/UnitTestProblem.cs b/day02/day02.test/UnitTestProblem.cs new file mode 100644 index 0000000..c398616 --- /dev/null +++ b/day02/day02.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day02.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("15"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("12"); + } +} \ No newline at end of file diff --git a/day02/day02.test/Usings.cs b/day02/day02.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day02/day02.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day02/day02.test/day02.test.csproj b/day02/day02.test/day02.test.csproj new file mode 100644 index 0000000..a5343ff --- /dev/null +++ b/day02/day02.test/day02.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day02/day02.test/testdata.txt b/day02/day02.test/testdata.txt new file mode 100644 index 0000000..25097e8 --- /dev/null +++ b/day02/day02.test/testdata.txt @@ -0,0 +1,3 @@ +A Y +B X +C Z \ No newline at end of file diff --git a/day02/day02/Game.cs b/day02/day02/Game.cs new file mode 100644 index 0000000..a9594e0 --- /dev/null +++ b/day02/day02/Game.cs @@ -0,0 +1,82 @@ +namespace day02; + +public static class Game +{ + public static GameSymbols GetOpMoveSymbol(this string opMoveLetter) + { + return opMoveLetter switch + { + "A" => GameSymbols.Rock, + "B" => GameSymbols.Paper, + "C" => GameSymbols.Scissor, + _ => throw new ArgumentOutOfRangeException(nameof(opMoveLetter), $"Not expected opMoveLetter value: {opMoveLetter}") + }; + } + + public static GameSymbols GetMyMoveSymbol(this string myMoveLetter) + { + return myMoveLetter switch + { + "X" => GameSymbols.Rock, + "Y" => GameSymbols.Paper, + "Z" => GameSymbols.Scissor, + _ => throw new ArgumentOutOfRangeException(nameof(myMoveLetter), $"Not expected myMoveLetter value: {myMoveLetter}") + }; + } + + public static GameScore GetGameScore(this string gameScoreLetter) + { + //X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. + return gameScoreLetter switch + { + "X" => GameScore.Loss, + "Y" => GameScore.Draw, + "Z" => GameScore.Win, + _ => throw new ArgumentOutOfRangeException(nameof(gameScoreLetter), $"Not expected gameScoreLetter value: {gameScoreLetter}") + }; + } + + public static GameScore GetMatchScore(this GameSymbols myMove, GameSymbols opMove) + { + if (myMove == opMove) + { + return GameScore.Draw; + } + if ((myMove == GameSymbols.Rock && opMove == GameSymbols.Scissor) || + (myMove == GameSymbols.Paper && opMove == GameSymbols.Rock) || + (myMove == GameSymbols.Scissor && opMove == GameSymbols.Paper)) + { + return GameScore.Win; + } + return GameScore.Loss; + } + + public static GameSymbols ComputeMyMove(this GameScore gameScore, GameSymbols opMove) + { + return gameScore switch + { + GameScore.Win => opMove.GetWinSymbol(), + GameScore.Draw => opMove, + GameScore.Loss => opMove.GetLossSymbol(), + }; + } + + public static GameSymbols GetWinSymbol(this GameSymbols opMove) + { + return opMove switch + { + GameSymbols.Rock => GameSymbols.Paper, + GameSymbols.Scissor => GameSymbols.Rock, + GameSymbols.Paper => GameSymbols.Scissor + }; + } + public static GameSymbols GetLossSymbol(this GameSymbols opMove) + { + return opMove switch + { + GameSymbols.Rock => GameSymbols.Scissor, + GameSymbols.Scissor => GameSymbols.Paper, + GameSymbols.Paper => GameSymbols.Rock + }; + } +} \ No newline at end of file diff --git a/day02/day02/GameScore.cs b/day02/day02/GameScore.cs new file mode 100644 index 0000000..ecdde35 --- /dev/null +++ b/day02/day02/GameScore.cs @@ -0,0 +1,8 @@ +namespace day02; + +public enum GameScore +{ + Win, + Loss, + Draw +} diff --git a/day02/day02/GameSymbols.cs b/day02/day02/GameSymbols.cs new file mode 100644 index 0000000..995ed88 --- /dev/null +++ b/day02/day02/GameSymbols.cs @@ -0,0 +1,8 @@ +namespace day02; + +public enum GameSymbols +{ + Rock = 1, + Paper = 2, + Scissor = 3 +} diff --git a/day02/day02/Problem.cs b/day02/day02/Problem.cs new file mode 100644 index 0000000..467fe6b --- /dev/null +++ b/day02/day02/Problem.cs @@ -0,0 +1,63 @@ +namespace day02; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + //A for Rock, B for Paper, and C for Scissors + //X for Rock, Y for Paper, and Z for Scissors + + int totalScore = 0; + foreach (var line in lines) + { + var opMove = line[0].ToString(); + var myMove = line[2].ToString(); + totalScore += ComputeMatch(opMove.GetOpMoveSymbol(), myMove.GetMyMoveSymbol()); + } + // System.Console.WriteLine($"totalScore: {totalScore}"); + //13565 + + Result1 = totalScore.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + //X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. + int totalScoreStrat = 0; + foreach (var line in lines) + { + var opMoveLetter = line[0].ToString(); + var opMove = opMoveLetter.GetOpMoveSymbol(); + var matchScoreLetter = line[2].ToString(); + var matchScore = matchScoreLetter.GetGameScore(); + var myMove = matchScore.ComputeMyMove(opMove); + totalScoreStrat += ComputeMatch(opMove, myMove); + } + // System.Console.WriteLine($"totalScoreStrat: {totalScoreStrat}"); + //12424 + + Result2 = totalScoreStrat.ToString(); + } + + static int ComputeMatch(GameSymbols opMove, GameSymbols myMove) + { + var localScore = 0; + switch (myMove.GetMatchScore(opMove)) + { + case GameScore.Win: + localScore += 6; + break; + case GameScore.Draw: + localScore += 3; + break; + } + localScore += (int)myMove; + return localScore; + } +} \ No newline at end of file diff --git a/day02/day02/Program.cs b/day02/day02/Program.cs new file mode 100644 index 0000000..1135e79 --- /dev/null +++ b/day02/day02/Program.cs @@ -0,0 +1,44 @@ +namespace day02; + +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + + // //A for Rock, B for Paper, and C for Scissors + // //X for Rock, Y for Paper, and Z for Scissors + + // var lines = File.ReadAllLines("input01.txt"); + // int totalScore = 0; + // foreach (var line in lines) + // { + // var opMove = line[0].ToString(); + // var myMove = line[2].ToString(); + // totalScore += ComputeMatch(opMove.GetOpMoveSymbol(), myMove.GetMyMoveSymbol()); + // } + // System.Console.WriteLine($"totalScore: {totalScore}"); + // //13565 + + // //X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. + // int totalScoreStrat = 0; + // foreach (var line in lines) + // { + // var opMoveLetter = line[0].ToString(); + // var opMove = opMoveLetter.GetOpMoveSymbol(); + // var matchScoreLetter = line[2].ToString(); + // var matchScore = matchScoreLetter.GetGameScore(); + // var myMove = matchScore.ComputeMyMove(opMove); + // totalScoreStrat += ComputeMatch(opMove, myMove); + // } + // System.Console.WriteLine($"totalScoreStrat: {totalScoreStrat}"); + // //12424 + } +} diff --git a/day02/day02/day02.csproj b/day02/day02/day02.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day02/day02/day02.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day02/day02/input.txt b/day02/day02/input.txt new file mode 100644 index 0000000..3ac077e --- /dev/null +++ b/day02/day02/input.txt @@ -0,0 +1,2500 @@ +A Y +B Y +B Z +B Z +A Y +C Y +A Y +C Y +A Y +B X +B Y +B Z +A Y +A Y +C Y +C Y +A Y +C Y +B Y +A Y +A Y +C Y +C X +A Y +B Z +C Y +A Y +C Y +A Y +C Y +A Z +A Y +C Y +B Y +A Y +C Y +B X +B Z +C X +B Z +B X +C Y +B Z +A Y +C Y +B X +A Y +A Z +B Y +C Y +A X +C X +C Y +C Y +A Y +C X +A Y +C X +C Y +C Y +A Y +C Y +A Z +A Y +B Z +A Y +A Y +B X +A Y +B Y +A Y +B X +B Y +C Y +A Y +B X +A Y +C X +B Y +A Y +B Z +C Y +C Y +B Y +B Z +B Z +B Y +B Y +A Y +A Y +A Z +C Y +B X +A Y +B Y +A Y +B X +C Y +A Z +C Y +C Y +A Y +A Y +C Y +C Y +B X +A Y +A Y +B X +A Y +C Y +B Z +A Y +B Z +C Y +C X +C Y +B Z +C Y +A Y +A Y +B Y +C X +A X +B X +A Y +C Y +C Y +A Y +A Y +C Y +C Y +A Z +B X +C Y +B X +A Y +C Y +A Y +A Z +C Y +A Y +A Y +A Y +C Y +B X +C Y +A Y +A X +C Y +A Y +B X +C Y +A Y +A Y +B Y +A Y +A Y +C Y +B Y +B X +A Y +A Y +B X +A Y +C Y +A X +C Y +C Y +A Y +B Z +A Y +A Y +C Y +A Y +A Y +C Y +A Z +B Z +A Y +C Y +B X +B X +A Y +A Y +C Y +A Y +A Y +C Y +B Z +B Z +B Y +B Y +A Y +A Y +A Y +A Y +A Y +C X +A Y +A Y +A Y +B Z +C Y +A Y +B Z +A Y +A Y +A Y +B Z +A Z +C X +B X +B Z +B Y +B Y +C Y +C Y +B Y +A Y +C Y +A Y +A Y +C Y +B X +A Y +A X +A Y +A Y +B Z +C Z +A Y +B X +C Y +C Y +A Y +A Z +A Y +C Y +C Y +C Y +A Y +A Y +C Y +C Y +A Y +A Y +A X +A Y +C Y +B X +B Z +C Y +A Y +A X +A Y +C X +C Y +B Z +B Y +A Y +C X +C Y +C Y +C X +C Y +B X +A Y +A Y +A Y +A Z +C Y +A Y +C Y +A Y +B Y +C X +A Y +A Y +A Y +C Y +B Z +A Y +C X +B Y +A Y +B Z +A Y +C Y +C Y +A Y +B Z +C Y +A Z +C Y +A Y +B X +A Y +A Z +A Z +A Z +C Y +C Y +A Z +B Y +A Z +A Y +C X +C Y +A Y +A Y +B Y +A Y +A Y +A Y +B Y +C Y +A Y +C Y +A Y +C X +A Y +A Z +A Y +A Y +A Y +C Y +A Y +C Y +A Y +A Y +C X +A Y +C Y +B Z +C Y +A Y +B Y +A Z +C Y +B Y +A Y +A Y +A Y +A Y +A Y +B Z +B Z +B Z +A X +A Y +B Z +A Y +A Y +C Y +C Y +B Z +A Y +B X +C Y +A Y +A Y +B Y +C Y +B Z +A Y +A Y +A Y +B X +B Y +C Y +A Y +A Y +B X +A Y +B Z +C X +C X +A Y +C Z +C Y +C Y +A Z +B Z +C Y +A Y +A Y +C Y +C Y +C Y +A Y +A X +B Z +A Y +A Y +B Y +B Y +C Y +B Y +B Y +B Z +C Y +C Y +B Y +A Y +C Y +A Y +A Y +B Y +A Y +A X +A Y +B Y +A Y +B Y +C Y +A Y +B Z +A Y +B Y +A Y +A Y +C X +C Y +C X +A Z +C Z +B Y +B Y +C Y +B Y +A Y +A Y +B Y +C Y +C Y +C Y +A Y +B Z +B X +C Y +C Y +A Z +A Z +A Y +A Y +A Y +B Y +A Y +B Y +A Y +B Z +A Z +B Y +C Y +C Y +C Z +B Z +B Y +B X +A Y +B X +B X +B Y +C Y +B Z +A Y +C Y +A Y +C Z +B Y +A Y +A Y +C Y +B Y +C Y +B Y +B Y +A Y +A Y +A Z +C X +A Y +A Y +C Y +A Y +B Z +A Y +A Y +A Y +C Z +C Y +B Z +C Y +B Z +A Y +B Z +B Y +A Y +B Y +A Y +A Y +A Y +A Y +C Y +C Y +C Z +B Y +C Y +C Y +A Y +A Z +A Y +B Z +A Y +C Y +C Y +A Y +A Y +A Y +B Z +A Z +A Y +A Y +A Y +A Y +A Y +B Z +B Z +A Y +A Y +B Z +A Z +A Z +A Y +B Y +B Y +B Z +A Y +B Z +C Y +B Z +B Y +A Y +A Y +C Y +C Y +C Y +A Y +A Y +C Y +C X +C Y +A Y +B Z +A Y +B X +B Y +B Y +B X +A Y +A Z +C Y +B Z +C Y +A Z +A Y +A Y +A Y +C Y +C X +A Y +C Y +A Y +B Z +C Y +A Y +B Z +A Y +C Y +A Y +C Y +B Y +C Y +B X +A Y +A Z +C Y +A Y +C X +C Y +A Y +C Y +A Y +C Y +A Z +B Y +A Y +B Z +C Y +C Z +A Y +A Y +A Z +A Y +A Y +C Y +B Y +C Z +A Y +B Y +C X +B Z +C Y +C Y +B Z +B Z +A Y +B Y +C Y +B Y +C Y +B Y +A Z +C Y +B Z +A Y +A Y +C Y +A Y +B Z +A Y +A Y +C Y +C Y +A Z +A Y +A X +C Y +B Y +B Y +B Z +B Y +B Y +C Y +A Y +C Y +A Y +A Y +B X +C Y +B X +A Y +A Y +B Y +B Z +C Y +A Y +C Y +A Y +A Y +C Y +B Y +C Y +B Y +B X +C Y +A Y +A Y +B Z +B Y +B Y +A Y +A Y +A Y +A Y +A Y +C Y +A Y +A Y +C Y +A Y +B Y +C Y +A Y +A Y +A Y +C Y +A Y +B Y +B Y +A Z +A Y +C Y +B Y +C Y +A Z +B Z +A X +B Y +B Z +A Y +A Y +C Y +B Y +A Y +B Z +A Z +C Y +C Y +A Y +B X +C Y +A Y +C Y +C Y +B Z +A Y +A Y +A Y +C Y +A Y +C Y +B Y +B Y +B Y +A Z +C X +B X +C Y +A Y +A Y +A Y +A Y +C Y +A Y +B Y +A Y +C Z +C Y +A Z +B Y +A Y +C Z +C X +B Y +C X +A Y +B Z +A X +B Y +B Y +B X +C X +A Z +C Y +B Y +C Y +A Z +C Y +C Y +C Y +A Y +A Y +A Y +C Y +A Y +A Y +C X +B Z +C Y +C Y +B Z +C Y +B Y +B Z +A Y +B X +A Y +C Y +A Y +A Y +A Y +A Y +B Z +C Y +C Y +B Z +B Y +C Y +C Z +C Y +C Y +B Y +A Y +A Y +A Y +A Z +C Y +A Y +A Y +C Y +A Y +A Y +B Y +A Y +A X +A Y +A Z +B Y +C Y +A Y +A Y +C Y +A Y +B Z +B Z +C Y +C Y +A Y +A Y +B Z +B Z +A Y +B Y +C Y +A Y +B Y +C Y +A Y +C Y +B X +A Y +A Y +A Y +A Y +A Y +B X +C Y +C Y +B Y +A Y +C Y +B Y +C Z +C Y +B X +C Y +A Y +C Y +C Y +C Y +C Y +B X +A Y +C Y +A X +A Y +C X +A X +C X +C Y +A X +C Y +C Z +C Y +A Y +A Y +A Z +C Y +C Y +B Z +A Y +C Y +A Y +A Y +B Z +C Z +A Y +A Y +C Y +A Y +A Y +B Y +A X +A Y +B Z +A X +C Y +B X +A Y +A Z +C Y +B Z +B Y +B Y +A X +A Z +B Z +C X +C Y +B X +B Z +C Y +C Y +C Y +A Y +C Y +B X +C Y +A Y +A Y +A X +C Z +B Z +C Z +C Y +B Y +C Y +A Y +A Y +C Y +C Y +B Y +C Y +C Y +C Y +A Y +B X +A Y +B Y +C Y +B X +C Y +C Y +B Y +A Y +B Y +B Y +C Y +A Y +B X +C X +C Y +B X +A Y +A Y +B Z +B Y +A Y +B Y +B Y +A Z +B X +B Z +C Y +B Y +C Y +A Y +A Y +B X +A Y +C X +B Y +B Z +B X +C X +C Y +C X +A Y +C Y +B Y +B Y +A Y +B X +C Y +C Y +B X +B X +C Y +B Z +B Y +A Y +C Y +B X +C Y +A Y +A Z +A Y +A Y +C Y +A Z +A Y +B Z +A Y +B Y +B X +B Z +B Y +C Y +A Y +A Y +C X +B Y +A Y +B Y +A Y +C Y +C Y +A Y +B Y +B Y +B Y +C Y +A Y +B Y +B X +B X +A Y +C Y +C Y +A Y +A Y +A Y +A Z +C Y +A Y +C Y +A Y +B Z +C Y +C X +C Y +A Y +C X +B Z +C X +A Y +B X +A Y +C Z +C X +A X +A Y +C Y +B X +A X +B Y +A Y +A Y +A Y +C X +A Z +B Z +C Y +A Y +C Y +C Y +C X +C Y +B Y +C Y +B Z +B Z +C Y +B Y +A Y +A Y +A Y +B Y +C Y +A Y +A Y +C Y +B Y +B Y +C Y +A X +A Y +A Y +A Z +A Y +B Y +C Y +A Y +A Y +A Y +C Y +A Y +B X +A Y +C Y +A Y +A Y +B Z +B Y +B Z +C Y +A Y +A Z +A Y +A Y +B Y +A Y +C Y +C Y +A Y +B Y +C X +B Z +A Y +C Y +B X +B Y +C Y +B Y +C Z +A Z +A Y +C Y +A Y +C Y +C X +A Y +C Y +B X +C Y +A Y +A Y +C Y +A Z +B X +B Z +A Y +B Z +B Y +A Z +B Y +A Y +C Y +A Y +C Y +C Y +A Y +B Y +C Y +A Y +A Y +B X +A Y +A Y +A Y +C Y +A Z +B Y +B X +A Y +B Y +C Y +A Y +C Y +A Z +B X +A Y +A Y +A Y +A Z +A Y +B Y +B Z +B Z +A Y +A Z +A Y +B X +A Y +A Y +A Y +C Y +A Y +A Y +A Z +C Y +A Y +A Y +B X +B Y +C Y +B X +C Y +A Y +B Y +A Y +C Y +C Y +C Y +C Y +A Y +C Y +C Y +B Y +A Y +C Y +A Y +A Y +B Y +A Y +B Y +C X +A Y +A Y +A Y +C Y +B Z +C Y +A X +A Y +A Z +A Y +B X +C X +A Y +B Y +A Y +A Y +B Y +A Y +C Y +A Y +A Y +B Z +C Y +A Y +A X +B Z +A Y +A Y +A Z +C Y +A Z +C Y +B Y +A Y +C X +B X +A Y +C X +C X +A Y +A Y +A X +A Y +A Y +A Y +B Y +C X +A Y +C Y +C Y +A Y +B Z +A Y +C Y +B Z +A Y +C Y +C Y +B X +B Y +B Z +A Y +C Z +C Y +A Y +C X +A Y +C X +B Z +A Y +B Y +A Y +C Y +B Y +A Y +B Y +B X +A Y +B Y +C Y +A Y +C Y +C Y +A X +C Y +C X +A X +A Y +C Y +C Y +C X +C X +C Y +C Y +C Y +A Z +A Y +B Z +C Y +C Y +A Z +A Y +A Y +C X +A Y +A Y +A Y +C Y +A Y +C Y +A Y +A Y +A Y +C Y +C Y +A Y +B Y +B Y +A Z +B X +B X +B Y +C Y +A Y +A X +A Y +B X +C Y +B X +C X +C Y +A Y +A Y +C Y +A Y +C Y +A Y +B Z +C Y +A Y +B Y +A Y +A Y +A Y +A Y +A Z +C Y +A Y +B Y +C Y +C Y +A Y +C X +A Y +A Y +C Y +C Y +C X +B Y +A Y +A Y +A Y +A Y +C Y +A Y +B X +A Z +A Y +C Y +B X +A Y +C Y +A Y +A Y +A Y +C Y +B Y +A Y +A Y +B Z +C Y +C X +A Y +A Y +C Y +A Y +C X +C Y +C Y +A Y +C Y +C Y +C Y +C X +A Y +A Y +A Y +A Y +C Y +B Y +C Y +A Y +A Z +B Z +A Y +B Y +B Z +C Y +A X +B Y +C Y +A Y +A Y +C Y +A Y +A Y +A Z +B Z +C X +B Y +B Y +C Y +C Y +C Y +A Y +A Y +A Y +A Y +C Z +B Y +B Z +C Y +C Y +A Y +B Y +C Y +A Y +A X +B X +C Y +A Y +C Y +C X +C Y +A Y +A Y +B Y +B X +A Y +C Y +A Z +B X +C Y +B X +A Y +B Z +A Y +A Y +B Y +B Z +B X +A Y +B X +B Z +A Y +C Y +A Y +A Y +A Z +B X +A Y +A Y +B Y +A Y +B Z +B X +C Y +C X +C X +C X +A X +A Y +A Y +A Y +B Y +A Y +A Y +A Y +C Y +B Y +B X +B Y +C Y +A Z +A Y +B Z +A Y +C Y +A Y +A Z +B Z +C Y +B Z +A Y +C Y +B Y +C Y +A Y +C Y +B Z +B Y +B X +C X +A Y +A X +B X +C Y +C Y +A Y +C Y +B Y +A Y +B Z +A Y +B X +A Y +C Y +A Y +C Y +C Y +A Y +A Y +A Y +C X +B Y +B Z +B Y +A Y +A Y +A Z +B X +A Y +A Z +C Y +B Z +B X +A Y +C Y +A Y +B Z +A Y +A Z +B Y +C X +A Y +C Y +C Y +C Y +C Y +A Y +A Y +B Y +A Y +C Y +A Y +B Z +C Y +A Z +C Y +A Y +A Z +C Y +B X +C Y +C Y +A Y +A Y +B Z +B Y +B X +A Y +A Y +B Y +A Y +A Y +B X +B Y +A Y +C Y +A Y +C Y +C Y +B Y +B Y +C Y +A Y +A Z +A Y +A Y +A Y +C Y +C X +B Z +C Y +A Y +A Y +C Y +A Y +A Y +A Z +C X +C Y +A Y +A Y +C Y +C Y +A Y +A Y +C Y +C X +A Y +A Y +B Y +A Z +B Y +A Y +B Z +C Y +C Y +A Y +B Y +A Y +C Y +B Z +A Y +A Y +C X +C Y +C X +A Y +A Y +A Y +B Y +C X +A Y +B X +B Y +C Y +A Y +C Y +A Y +A Y +C Y +A Z +A Y +C X +A Y +A Y +C Y +C Y +C X +A Y +A Y +C Y +B Y +A Y +C Y +A Y +B Z +A Y +C Y +A Y +A Y +A Z +A Y +B Z +A Y +A Y +A Y +A Y +A Y +C Z +C X +A Y +A Z +C Y +C Y +B Z +A Y +B X +A Y +A Y +A Z +B Z +A Y +A Y +C Y +A Y +C Y +B Z +B X +C X +A Y +B Y +C Y +C X +B Y +C Y +A Y +A Y +A Y +A Z +B Y +A Y +C Y +A Y +A Y +A Y +A Y +C Y +C Y +A Y +A Z +C Y +B Y +C Y +C Y +B Y +A Y +C Y +B Z +A Y +A Y +B Z +C Y +B Z +C Y +C Y +B Z +B Y +A Y +C X +C Y +B Y +A Y +A Y +A Y +B Z +A Y +B Y +A Y +C Y +A Y +A Y +C Y +A Z +A Y +C Y +B Y +A Y +B Z +C Y +A Y +A Y +C Y +B Z +B Z +A Y +A Y +A Y +A Y +A Y +C Y +A Y +A Y +A Y +A Y +C Y +A Y +C Y +B X +B Y +A Y +C Z +B Y +C Y +C Y +A Y +C Y +C Y +A Y +A Y +A Y +A Y +B X +B Z +C Y +B X +B Y +B Y +B Z +B X +A Y +A Y +B Y +B X +A Y +A Y +C Y +C X +A Y +B Y +A Y +B Y +B Y +B Y +C Y +A Y +A X +A Y +C Y +B X +B Y +A Y +A X +C Y +C X +A Y +A Y +A Y +B Y +C X +A Z +B Z +A Y +B Z +A Y +A Y +A Y +A Y +B X +A Y +C Z +C Y +C Y +C Y +B Z +A Y +A Y +B Z +B Y +A Z +A Y +A Y +B Z +C Y +A Y +C Y +C Y +C Y +B X +B Y +A Y +A Y +A Y +A Y +B Y +A Y +B Z +B Z +A Y +C Y +C Y +C Y +A Y +C Y +B Y +C Y +A Y +B Y +B Y +B X +C X +A Y +A Y +A Y +B Y +C Y +B Y +C X +B Y +B Y +A Z +C Z +C X +B Y +C Y +B Y +C Y +B Z +A Y +C Y +A Y +B Y +C Y +A Y +A Y +C Z +B X +A Z +C Y +C Y +A Y +B Z +B Y +C X +A Y +B Z +A Y +A Y +A X +A Y +B Y +C Y +B Y +A Y +A Y +B Y +C Y +B Y +A Y +A Y +B Y +C Y +B Y +C Y +B Y +B Y +B X +A Y +A Y +C X +A Y +C Y +B Z +A Y +B Y +A Z +A Y +A Y +B Y +C Y +B Z +A Z +A Y +B Z +C Y +A Y +A Y +A Y +C X +C Y +A Y +C Y +A Y +A Y +B Z +A Y +A Z +C Y +C Y +A X +C X +A Y +B Z +A Y +A Y +B Y +A Y +A Y +B Z +A Y +B Y +B Z +A Y +A Z +A Y +A Z +C Y +B Y +A Y +A Y +B Z +C X +C Y +A Y +A Y +A Y +A Y +A Y +A Z +C Y +B X +A Z +B Y +A Y +A Z +A Y +C X +A Y +A Y +C Z +B Y +C Y +C Y +B Y +C X +A Y +A Y +B Y +A Y +A Y +A Y +B Y +B Y +C Y +A Y +A Y +B Y +B X +A Y +A Y +C Y +B Y +C Y +B Z +A Z +C X +B X +A Y +A Y +A Y +C Z +A Y +C Y +B Y +A Y +B X +A Y +C Y +A Y +B Y +A Y +B X +B Y +A Y +C Y +C Y +A Y +A Y +A Y +A Y +C Y +C Y +A Y +A Y +B Y +C Y +B Z +C Y +C Y +C Z +A Z +B X +C Y +A Y +B Y +B Y +A Y +B X +A Y +B Y +B X +C Y +B X +B Y +B Y +B Z +A Y +A Z +B Z +A X +C Y +B X +C X +A Y +B Z +A Y +A Y +A Z +C X +A Y +B Y +B Y +A Y +A Z +A Y +B X +B X +A Y +B Y +C Y +A Y +B X +B Z +B Z +B Z +C X +A Y +C Y +A Z +B Y +B Y +A Y +B Y +C Y +A Y +A Z +B X +C Y +C Y +A X +C Y +C Y +B Y +B X +C X +A Y +C X +C Y +A Y +B Y +A Y +A Y +B Z +C Y +B X +A X +C Y +B X +C Y +C Y +A Y +C Y +C Y +C X +A Y +A Y +B Y +C Y +C Y +A Y +C Y +A Z +A Y +A Y +B X +A Y +A Y +A Y +A Y +A Y +C Y +B Y +B Y +A Y +A Y +B Y +C Y +B Y +A Y +A Y +B Z +C X +A Y +C Y +B Y +B X +A X +A Y +B Y +B X +B Y +A Y +C Y +A Z +B Y +C Y +C Y +B Z +C Y +C Y +C Y +C Y +C Y +A Y +B Z +C Y +C Y +A Z +A Y +B Z +A Y +B X +C Y +C X +A Y +A Y +B Y +A Z +A Y +C Z +A Y +B Y +A Y +B X +A Y +B Z +C Y +A Y +A Z +A Y +B Y +A Y +B Z +A Y +A Y +A Y +A Y +C X +A Y +B Z +A Y +B Z +B X +A Y +B Y +C Y +B Z +B Z +C Y +B Z +A Z +A Z +B Z +A Y +C Y +C Y +A Y +C Y +B X +C Y +C Y +B Z +A Y +A Y +C Y +B Y +A Y +C Y +C Y +A Y +B Y +A Y +B Y +A Y +A Y +A Y +C Y +B X +B X +C Y +C Y +B X +A Y +C Y +A Y +B Z +A Z +A Y +C Y +A Y +C Y +A Y +C Y +C Y +C Y +A Z +A Y +C Y +B Y +A Y +A Y +C Y +C Y +A Y +B X +B Y +C Y +B Y +B Z +C Y +A Y +C Y +C Y +C Y +A X +A Y +C X +A Z +C Y +C Y +A Y +C Y +A Y +C Y +A Y +A Y +C Y +B Y +A Y +A Y +A Y +C Y +C Z +A Z +A Y +C Y +A Y +A Z +C Y +A Y +C Y +B Y +A Y +B Y +C Y +B Y +A Y +A Z +A Y +B X +C X +C Y +B Z +C Y +C Y +A Y +B X +B Z +A Y +B Z +B X +A Y +A Y +A Y +B X +C Y +C Y +C Y +C Y +B Z +A Y +B Y +B Z +A Y +A Z +A Y +A Y +A Y +B Z +C Y +A Y +A Y +B Y +C Y +C X +A Y +C Y +A Y +A Y +A Y +C Z +A Z +B Y +A Z +B X +B Y +A X +A Y +A Y +C Y +C Y +B X +A Z +C Y +B Y +C X +A Y +A Y +B Y +C Y +C Y +A Y +C X +A Y +A Y +A Y +A Y +C Y +C Y +A Y +C Y +A Z +A Y +C Y +A Y +B X +C Y +C Y +C Y +B X +B Y +A Y +A Y +A Y +C Y +A Y +A Y +B Y +A Y +A Y +C Y +C Y +A Y +C Y +C Y +C Y +C Y +C Y +B Z +C Z +C Y +B X +B Y +C Y +A Y +A Y +A Y +A Y +B Z +A Y +A Z +C X +A X +A Y +A Y +C X +C Y +B Y +A Y +C Z +B Y +B Y +C Z +C Z +A Y +A Y +A Y +C X +B Y +B Z +A Y +A Y +B Y +C X +B Y +A Y +C Y +B Y +A Y \ No newline at end of file diff --git a/day02/problem.md b/day02/problem.md new file mode 100644 index 0000000..061ed00 --- /dev/null +++ b/day02/problem.md @@ -0,0 +1,50 @@ +--- Day 2: Rock Paper Scissors --- +The Elves begin to set up camp on the beach. To decide whose tent gets to be closest to the snack storage, a giant Rock Paper Scissors tournament is already in progress. + +Rock Paper Scissors is a game between two players. Each game contains many rounds; in each round, the players each simultaneously choose one of Rock, Paper, or Scissors using a hand shape. Then, a winner for that round is selected: Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock. If both players choose the same shape, the round instead ends in a draw. + +Appreciative of your help yesterday, one Elf gives you an encrypted strategy guide (your puzzle input) that they say will be sure to help you win. "The first column is what your opponent is going to play: A for Rock, B for Paper, and C for Scissors. The second column--" Suddenly, the Elf is called away to help with someone's tent. + +The second column, you reason, must be what you should play in response: X for Rock, Y for Paper, and Z for Scissors. Winning every time would be suspicious, so the responses must have been carefully chosen. + +The winner of the whole tournament is the player with the highest score. Your total score is the sum of your scores for each round. The score for a single round is the score for the shape you selected (1 for Rock, 2 for Paper, and 3 for Scissors) plus the score for the outcome of the round (0 if you lost, 3 if the round was a draw, and 6 if you won). + +Since you can't be sure if the Elf is trying to help you or trick you, you should calculate the score you would get if you were to follow the strategy guide. + +For example, suppose you were given the following strategy guide: + +A Y +B X +C Z +This strategy guide predicts and recommends the following: + +In the first round, your opponent will choose Rock (A), and you should choose Paper (Y). This ends in a win for you with a score of 8 (2 because you chose Paper + 6 because you won). +In the second round, your opponent will choose Paper (B), and you should choose Rock (X). This ends in a loss for you with a score of 1 (1 + 0). +The third round is a draw with both players choosing Scissors, giving you a score of 3 + 3 = 6. +In this example, if you were to follow the strategy guide, you would get a total score of 15 (8 + 1 + 6). + +What would your total score be if everything goes exactly according to your strategy guide? + +Your puzzle answer was 13565. + +--- Part Two --- +The Elf finishes helping with the tent and sneaks back over to you. "Anyway, the second column says how the round needs to end: X means you need to lose, Y means you need to end the round in a draw, and Z means you need to win. Good luck!" + +The total score is still calculated in the same way, but now you need to figure out what shape to choose so the round ends as indicated. The example above now goes like this: + +In the first round, your opponent will choose Rock (A), and you need the round to end in a draw (Y), so you also choose Rock. This gives you a score of 1 + 3 = 4. +In the second round, your opponent will choose Paper (B), and you choose Rock so you lose (X) with a score of 1 + 0 = 1. +In the third round, you will defeat your opponent's Scissors with Rock for a score of 1 + 6 = 7. +Now that you're correctly decrypting the ultra top secret strategy guide, you would get a total score of 12. + +Following the Elf's instructions for the second column, what would your total score be if everything goes exactly according to your strategy guide? + +Your puzzle answer was 12424. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day03/day03.test/UnitTestProblem.cs b/day03/day03.test/UnitTestProblem.cs new file mode 100644 index 0000000..12da423 --- /dev/null +++ b/day03/day03.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day03.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("157"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("70"); + } +} \ No newline at end of file diff --git a/day03/day03.test/Usings.cs b/day03/day03.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day03/day03.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day03/day03.test/day03.test.csproj b/day03/day03.test/day03.test.csproj new file mode 100644 index 0000000..ebc75f1 --- /dev/null +++ b/day03/day03.test/day03.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day03/day03.test/testdata.txt b/day03/day03.test/testdata.txt new file mode 100644 index 0000000..9919ffa --- /dev/null +++ b/day03/day03.test/testdata.txt @@ -0,0 +1,6 @@ +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw \ No newline at end of file diff --git a/day03/day03/Problem.cs b/day03/day03/Problem.cs new file mode 100644 index 0000000..1cba47a --- /dev/null +++ b/day03/day03/Problem.cs @@ -0,0 +1,68 @@ +namespace day03; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var totalScore = 0; + foreach (var line in lines) + { + var linecontent = line.Trim(); + // System.Console.WriteLine(linecontent); + var h1 = linecontent.Substring(0, linecontent.Length / 2); + var h2 = linecontent.Substring(linecontent.Length / 2, linecontent.Length / 2); + var commonLetter = h1.Intersect(h2).First(); + // System.Console.WriteLine(commonLetter); + var score = ConvertLetterToScore(commonLetter); + // System.Console.WriteLine(score); + totalScore += score; + } + + // System.Console.WriteLine(totalScore); + //8153 + Result1 = totalScore.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var totalScore = 0; + var groupNo = lines.Length / 3; + for (int i = 0; i < groupNo; i++) + { + var elf1 = lines[i * 3 + 0]; + var elf2 = lines[i * 3 + 1]; + var elf3 = lines[i * 3 + 2]; + var groupLetter = elf1.Intersect(elf2).Intersect(elf3).First(); + // System.Console.WriteLine(groupLetter); + var score = ConvertLetterToScore(groupLetter); + // System.Console.WriteLine(score); + totalScore += score; + } + + // System.Console.WriteLine(totalScore); + //2342 + Result2 = totalScore.ToString(); + } + + public static int ConvertLetterToScore(char letter) + { + var score = 0; + if (letter >= 'a' && letter <= 'z') + { + var baseLower = (int)'a'; + score = letter - baseLower + 1; + } + else if (letter >= 'A' && letter <= 'Z') + { + var baseLower = (int)'A'; + score = letter - baseLower + 27; + } + return score; + } +} \ No newline at end of file diff --git a/day03/day03/Program.cs b/day03/day03/Program.cs new file mode 100644 index 0000000..c906fe7 --- /dev/null +++ b/day03/day03/Program.cs @@ -0,0 +1,15 @@ +namespace day03; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day03/day03/day03.csproj b/day03/day03/day03.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day03/day03/day03.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day03/day03/input.txt b/day03/day03/input.txt new file mode 100644 index 0000000..83b5de3 --- /dev/null +++ b/day03/day03/input.txt @@ -0,0 +1,300 @@ +VdzVHmNpdVmBBCpmQLTNfTtMhMJnhFhTTf +FgqsZbqDDFqRrhhJnsnLMTfhJG +bRRRPrRRwSwbDqgjvDZbRbQzpzmQVWCzzBdvQBFCzlWV +GcDdRdvhRssRhGDdShCRtqWjlQzqWgqzNfNjfQWWjt +mwwnnPFwmVrPmJmzfNzqCjQCbgVlgC +nPnHHLrHwmJTrCTJpThBscBSdSLGZvZBvRhZ +RVQQcVlcSRclfZCCCnMJJTSTnC +NdHwjdwjbBBZrrZrbJDZJJ +wmhjGGBGwwmjtjtdPlfRcpVQlhRppVJF +pplbNBPPrppllrFNbpvppSTcwqcWFhTTShhJDTchqd +RGzRfLjjmZmfmwLftTWhStStJWTdWmDm +nfsMjQssnpPvNnrPrw +SjjBgllzlQjBZvlBBgcFbgJHsMhJqbMHPggJbM +hRLRVDdRRWnJqnnHTqMCnH +GRfLddRRpVhNVrWSjwQQzSzcGSBQSc +qMwNqqBdQdnTVBBVVhMVnVFzTHPggTPjGRDzvPTjjmvPDj +sbSrWJpStrtPtRPttzmmDD +pfbJJcbsrcLpWLllsnFmcqcwQncnQQqVNQ +RBTWCMwCwdZThPZcZZ +pVmVpHLFFFHHVgVmvNmHSQNvddlPPzZJMPcdhclhjczLdZMP +vnnNnFStGMRDwWnn +fWDdJTpDJzdBBBdmDSbSRHRwPqbPbHgSbz +slQtQvNsMVvrrgPRgRglnhwWPH +sGMMQFrsjvNMfWmdpfFDFZBf +vnMRMWCMJwWWwwWPjmSdVmLdzvVbLrhL +HsNfDHQlZpNqfQzbLbrqhjLmVdjd +dfDZQsNpstHHHptZDDtZWgngtgBMPMMRwCPtBBGW +HwQwwbwFNWHwHBVFQFLQzRznZnSzcjjjpPbcPpSP +vTfTJsCmsftJZmTSSdPvzdjRSvPdjd +TrGtTJfmGDfDhrhJJJsqrZhDBFLHHLLQWFwwlWBVBBVwgLFD +FFTJRLccQgmTbSsbGm +PBPPqCvCwqwhQQVhQngmVmSgglmGnHbnmb +zqthvtQPBfCCzPwQPtwQzPwNLfNRFNLdLRLFRFFNLFdFdW +nszjQnsPwjznzCCrhJqvjqhmBv +tFWdHGWFGtctlNNpZBBhmqTrrbWqvTBT +dlFtcpHDVVVHFdNGHGpGfQgsPDzSMsQwwPwgLLBQ +TzQqTJGvnnSzqrWTnvfbbcflQcVltfcCMPVM +jFjNZFFJLpFwmBwblcpptcVtfbbVlR +jmmJdBBLNdGDWDDrdzqn +pzddqQmGgbqgGpbJmmdnLZDCRZnZvFlLRZLSlLRT +rVwchcBBMwVBHhHTZCTSGSCRTZlTDr +HtccPfjfBhMtVBGHWpNqJdJdpjNJppWz +WThTWWhtPbZRvvWbbvRTSRMjVRLLgFssgLpVsfSF +JdwrlJcCwfzdqwwjsjzpLMgVsMFgML +lQrwHNGJHClvTmfhBmPQmt +lbRLhcLRpLJzgdGddF +qvhwqDDCVtBDVhfMVGFnzGGzTBnGzGGgFg +VjCwCWCMtjVDtChvQhtffcSmHpNWrrcHZHHZpplWbp +DJVDVdvpmZdPgrCbgbgCJC +lzczcWwwznGhBgPSvTlCrNgqNC +wGzzQhzGGsBBGRBcQwGwnwjmmRHpRfmmMpppMjjHDvLL +HJjJQWjFmmWtFmJTMchghhDwNMhVMWML +SznPSRfRSSPdrrPSShbDVhbLPwcwGGwVNh +ddRfzdRrCrRsZDSnFjspvFvqFqFqTvJt +lflfjQfjvljfbfMLTTDCmHNLNVbL +HSJnRrrJZJssnGRrnsrcqqRnDCLBMhVCTLVLhVNVJBBBhhBm +SsrGGqqnSsWSnnqWHSrPfzftvFdvWlwfQgQwWvzz +nQlsGnFGwwqNJWmJJjpplt +HMTLPTRdvsTCCThDCZdLdLDNNpJBWJbjJMpBmbtNptBWmm +DLCzPzTzZDdLdGSGfSGrsnQGzr +LNPPLHNPHQNQSBFDWDPgggFv +hszfWCWJhrBMsSSBgvFD +GGZjfmJTjmZfrJrZrZJRGwNQnlLNHWjLVjlwdVNHpV +BdNVdTcGVclmTwrTnwPwrHCr +zttBWzfLsCggHPwDrf +szsWSMbWzzbqBbzJjtjsvMzzvdmdVpGllpcRNZZhmRpZcGGc +CjdbMmmmZFnzzgHlttGBVqtBGtsldG +LvPPWNcFSSRslWhBsllT +ppccvLPpcSNwLLwrDNNpLvwJHCMDmbCJbFzgmZZmFgbgnM +TTNRwZqhcTTjsNTTsmrJlvrmmmqqHSrlJH +fLQCCdtcfCDDVbVVQdFbQbdJHMHrJHrHnMllHdMHPrMdln +WfQLQWWDbwRTWcRssN +HQGQWHPDHNjMNQGNWNTWCvZllzqFZqzvvzhCtvFj +DfgwdgfcFpchztvt +sRggdwwVdgmnSTnnDBPBNWLn +WbCZCfTVTTJjSwGdWNDGGw +MMRqggMsqhlmlhrssHgRnRmRvdzdczvdNGNLzScGDrNzrLNc +lRqsnRhmqqQnQpgQMlgDqRfBTJVFbJZQtBCbZQJVZFFb +JnhQcCnmLDsmgmgr +bbMZppRFGGRPfBMMRGMZssTTrLlLfsLlVLdsLsdn +GZGSpPGMZtGGPFFRGBCwhvwjjcnJctvQcvHq +vvrPrHZMGJNRMnqn +BVChWWcDVWsBwCWwGrJNhRLJJnJtLqnq +cjDfcfpWWsfWccBsHgPgrPTdpZbbgggv +GshtVtVtjSCVtVvVGtlVvFZLMvLRZmHmZwbLwZdLdZmR +JWzNDQzjcgJgQBJgzgMwLLHZZcdPwRLwRdHZ +QWTppBWfDrrNBTTfffhFCpVSjnhCGsFtsqSl +nmbCnzHHNzCjCJHJNSCWHLBLrvBrrSGRBDhrDRLrGL +TVtPllwcgdmTRhLQTQhT +fdFtccFcpPmggfdfNzHzCMsbCnWnJs +fMgddvjgRRvjvjVJVdTlZGGtGnrlnqTccNjl +HHSFSWSmmpbBpZlGncrNGbNtrn +WDWBDDBDBDCwPBWBDWNQDgzvVvLRvsVLRwvwdJVLwL +ZSmmvcpsmcJmJvqgBZgZqqtCtZjl +WhDwhFSDgtBFjnFg +rTrSTLWTTHNMNwNrMVddwNNhsmJGQcRsRcJGsJzQJsrzPsPm +GBtLmPsCQqsGqgghZHDzzgLbFz +zjjVTzTlRjRJfznrvrfpnNhFSghbbNFgHrbHZbDHbH +vpfcTJVpcVlfcQPMPCGzCBsd +HMhZNffcPZfNMrzjjFdGcJDjvJ +VSBVVLlSQQmTVSWpSQzDrHzTTvDvFjFdGGzT +mQSplVHWbHLSgWQnShNwsZMZPfbsNCRNCt +MMqvDzLwZzlMqQfdGWPfgPffPglH +ShTcJshsrRdnrdfrrfHp +VVRtFhsCJVJVvwQqDdbDQd +dmnNMlFNvmvljnbpMWNDFQvfQJJGvfPCfHGgQQgcJg +bRVzLBSSTRBRBBrwTrVtRwCfcGHcsJgJgzgGsggHCzcC +ZbtVTTrrqrSSVwhqqwBRwFWMDFNdjdZpWjdDDppjMW +MTzqtbLtwFzJgbHgfbdWWH +VMNBjNVjvNfhhhhfNPhP +jmGMvlDZZnVMtzlwzqqCpwFt +PpzGspGmpPsFLrTnTLzzBg +QCWvfjfWjRPFZgrvqrBvTg +wwNRCNQQVNRWjNWfQbHCCClHGDGJdGhpdhtPGhltDlJD +dhbpGzhllzGlPvnzNcvtNVnc +gcFMsTJDMMwrZqfjjqvvfnPtqJ +sWRWTRFwrTgLDDFWgMsTlpSlpbSCdWWdcbmpChGd +QccdFFFcFbcQPQPHMgpPMp +NJlNSSMLDfJfmlSqHZRNpRqNBRPRPq +LlMmJfvDVVTJSmVMscsCFtvwcjWjrjCj +NVVMGWFSMRVGWSthwhTJWzcJCcJsTs +jqRLqlfRZcmjcCzT +rlRRrdrflpdvPbHpflfPlfDBgBMQpGVQMgpVDGMggBDV +VwRhccRsnQStRhtGQVQVsmjgDgqJdggDjqLDgJlLzmLl +BWFZpWHBNCBCNBzBNvWBpzHZqqlMqgNdlllDdqDgJDLlfDdd +pFbTrrrBzbzTtSwStQnnsrVn +DRfFbFqzbddfPFtsJnJRsnClJRsn +cgjgQgWvSLVQgmWWgWVjVSSSBTltThLnqJssnTCZsTThntZT +qjwpSrmWgcSrGMfdFDFdwHFd +RWjDDWDjDNjjgDtSRRgjcjzFpnzwdFbFNdbFbpnldwFF +vQfPfTQJbZdThTzL +PrBQJQsfQqrrbfmPqMBfJbggjRVgWjttsHRSgRctDjSs +NgqNWqqWWdnJdqpBNFtCmJGCDHttDGDsHsHm +BjvzhRLTrTBQhTMQRjRRcjPGtmDCZZDZSCmmMSSZmVmSSt +vQzRvRzQcPcvfQzRnddppFgnFfWwBFlb +nnPvfvgrtPDHgvvGTRRRPZQGpGCLLV +FlBsBdbllFdfWpbGMCVMZLVbZQ +lhchNcqFsJBlBszztvwHjvzgrzmzffgH +zZhdjTpJJpjmmpPZhvqnnZHqZcggvgMbgv +tFpFQFSFtBGlFNwFfNMnHfbHcnvcvcfvcqrM +GBFlNLSNVGVSSGtQSLLBBlNtphDdzpmmPmTPhRmdzdVCCDdR +rpRCCDLpmnCdJCjn +vMhSFvgsMGLmnmWMmm +wVqFFvwvPPHhFhhgHPwHshpqrDDzqlfRbpftRLblrllr +CRNDzdJCVDWzVgDjdjzRJzWRMTbHsMNZNbZMMbsfhTtMTLMB +wSlwQcSpqPpcqcqFSqpwslsTfZtLhtlthtBHtTMZ +SPGFGFFmpcPGDrWDmjDJVffR +dsmdtJthJphWqHRPnRRsvvnnfR +cDBMDDDlBZglDZTMDfzVvNRrvNPVHzRRTV +PGMCCDClBDDbbFqmmhqQdpWGmmWp +BJjcGhcvCnBdGHsmHSzZDzSDMHmRMQ +qLWPLVrTwWlwwwrfrFfGDNmDQRMbQMzzmmbQLNMM +rVWrFlGqlqwVwVGgWGphnvgBBsnvsjdBnCBnBg +sNNsfBsmcGmgNTcHHSpnTWHnpV +QlrhlrlMglhDQrdFblvFtMdnDWwSHDWWwnTSjLwVDSwwwT +QtdMvltZhbFlPPZbQtQthZQdqCsJJGzBqqCBmCNCqgRCBsfP +SZnQnnHRWRQRVjHnqlJTQPfdlqfJftqG +pDzmbDBFbBLvvzttfdlTTl +gsDLLpcmsSZVwlnRsV +LHsWjwjWqCLsqCHcLsjdLqcdbpMGZPPtBhthbZBpBhMllwPG +VFnVbbvJSfbgphSpGlhRBBSP +JrrTgmFgzvNbrmNnmnvzgTLjCQWDLDCsTjssjqcHLc +QmwwqTqsrdqNNqgtvnVDVcGNNtvv +WBFBpzzjSJBJzJbfntgPzVzcvPnzDf +HcpbHZJBFpjpcSZrZsdRQZrCwrwd +JqmLmbtTWThBTWvWGVSrrVDsSGSG +wwzRzNjNNbsPVPds +jfgQRZwpQclQfffHgpRpwpfTcqtLLqCbbFFFLmbmTTBnFB +fGpcccNNqcctqGMprvMPmbbzFSflSRzPBBlBbS +JCjnjTZTTGPSGmTFPb +ZWHhJjHLDVDgHLLDGjnhctsstwqctNwWqNwwQrtv +sDwQhcwhBDDwrhGsQnRBQHHMHHMNJMZFCFRbCRftMM +zjjlmjqfdTqlWdzTqmLzlzVjNCHJNHNFMFtbJNZgVNMMCCtN +vPTfLmPTLWBsPDnSscnS +ngznwDPPTzhPPDCTQnTTDQBQqHNNrHFVppbbjRFFqFhHqRqr +tZJtcGsGtLLcctRqVBbbqrspbHNq +BmZSvGBMdWPzMPgnnz +MpNWPVNWWZWVVNZHVcvJjgBjJMStMJSjjg +rzdCzrCTTLRCslvJDSjjdScgDm +RLhCQzqTCssThRQzRzwGQrrCFffbfWppNpWNWVcHqZbHpVPp +zQzCVWdSSjCdjpchWcGftflGZcgG +RwnJTJwmvFHTBFmtBccZZfBGMstllM +wwvvHRwqDnHFrmqnrSbQVVQfSbqQjbqjbQ +ttDftStSlftPgSHmJbFwnMnFwzbrLHMMzz +GqTBqhBqBvppBvMMTznrCbCnLwfr +RBjjpZZvvZqGcNhjjpNmDPfDcsgfDfgScsQQQg +rsSFccvBHppHPsvQrSHSprFjnbLGdbzLfbGLLtLjjzLzvl +JWWJhmwwTDTGtnzlhdbtLG +CWNqWRNCwnCJVppQFFFFNrgHBB +MSRVnMjnVRVnPlcsrtMtschgDl +NWHBwJBwBBQCHHqwWQGBNgdrFFtsthcqdltdDsqttq +CCTTGCNCCBfNJNNWbGGnvVzDSRfDRSZvLPSzRn +MpRfjRjWpZzzzRzZSpjzZjTCQcGdHLWNGqdBdcBWWBLccn +lrbrsPQDPQglDtwggcLCqnCdNNdHBLsqNd +blwbJggvgbwlvQbvtgwmvVwRfTzfMMjFVfSFjZjMTSTSzj +ttSGjHWVrwWrWWvhzvhmhDfR +qMBdNNsccQgfDRzRmqlhRl +gQJdfJPdQBsMggMjPrTCLjrGrCrtVT +tGFdlwDwGFdNtStghWWdQFSnTVfCfZhrfVTVCVprnRRhVn +cLsBPQJsQPmbmPHTnRRnHprCVfns +MjmvPqqQjPbQzjLwwDWDSlzSlGSgwl +NSCpFgfbscbZZZwrtgPZJT +zGCQlVGmmQGVqqJwGtHZGrPHHRTH +qQvVmvzmqCdhhjzCQLjljLQMnMDSFWcSfnMfpbfnNcFFbFDN +zFgqjQBmWNlWlfHrHdLc +wnbCpSSZZTJSJSnmdrtHfGtftlcpltpH +ZSwhVPPJgNVmNFzs +WNVJthVHRRfLqpqN +gdCGcCgJBCrgScRLzbjQQLfRRR +SCFdGSFvlhTJsnvW +FFZwFZZwRmFFhHtNLNLGRtsqjLMt +gbDnnrMbMCffMPbPLNjGNlcppNtspp +rgbzrzDrgVgnrBzFWMWmWBwHWHShSB +zjRVjDqzRjvSBnBGGsfsrFsV +fLccLLZpJMctwJWWWJWpJGCwFwsgnngFBPsCnnTBPT +LbJlZNWMtpMlHRNHzdfSDfdj +VGbbnJGSTsVTssTTnVVWMtfBBmvftRHfHBMJJfZp +ghqtrzgPrjdzQCjmZMHfRHZHBmQmmB +gltFtDqFVlTVWlTl +HqNqZDTvNvVTLPSTvzfrfHfdndffwnbdnwrH +MpSJlFcMJmcpFlmClcMcRnWbWtthrnfwnCGrrWfrwC +RjcJJmSFMRQpMRFjMNVvTZjNPPvLTBPBBB +MzClDtlzJzFzNGGm +bjcLRHlTBsFJGmRm +HcPSSfTSpLZLbSwtrtvMnlDCDPCl +gWWgQJCsVhgRLCWsdjpmcBHvfvrrnvCvBB +TqDtztqtStlbNTPtllqZpvmcFHjNjvjNvHvmrrmj +ztPPGZqTPSbJgchGgwRQgQ +wVrdtTqtCCvbNgbNTTDN +mhGzWhGzMGWGrRmbFLBHZRNHNvZvgB +hhGhShpnsSrqVCVSSj +HnlbmGnlHZHnlBcjgwfDVfwLsGLGLDgR +WhWMWTvQPWPLDMFRCDMsVD +QdzJQPSPZqJnJRnZ +TTjTjFBcRBGjwsDTBLmrCftfRVrrCftCVNRP +WnqbJWnnQJhSqVfVPfDnggfrVN +hSlDMllvhbQqllZlSWQdSQTBjsFHBjTwGdHBTBszLzcc +rNWqWDLZWcqFqLLLgQQJnndnQdNzzJVMzd +cPtsPvChtRsGswHPGbwcPcdVnpzvnmBmVvJBJdJVJdzn +PfRfRGtsHsSRftbbbbHhwCCsjZgSTgSZWDTcgDZjLqgqFWLq +BNzPnPJNNMwHJRhBGRWRdjFQddFlFjWd +npbZrgnLSCSrWFjjdlZGlcDF +gqtmmngSbmgHJqfqzNBHBJ +stgzttBPRRRdpSVVpdpS +WJFcLQmJZHcCFLJmcZLMfbpGSWMNpGftSSpMrb +mcvvQvHmtLCJmHZQHZHCDHJJnjqPjjPzwvwhnwPqTjPBzPnB +DDmbbPqgFSbSQPtPQJttrltJ +CRfcnZWmRRhJNVtsVnQlsp +fcBvWvWzcZWCzTTCTTvccFMBHGDdSwGFFbqwFSGSmF +tCRBPCPRjzsJszBmtjmCvSpHcppJpvZdHHHcHZJG +qbrlLnWlQDQDNvmHHHHcrZZvdm +nmnWnnWmgQsCFzFCRVCg +sHMHCDZfcwMcRcLMcZDCRCHMPdJqgjvVdvqgdgfdJbQgvWQb +FFhTzmzGrnmtjTBjBBprrmFtqGgQqvVdPbbgqQQWJvvWJQqV +TrNjrnFSlwNZNlNL +JQGdsdzSzsdFQFSdssnndNlZjNPTJZNljVjTPhVPhT +GgGLfRmHGLhNVjjNTLhV +HvGvwpbHHRwpBrvBgSSzSFndtzndCrsFMd +DptFshMrhDhDwmPPhwSNhmmS +RLdcdRvBjnvRVcvlcLbCcbCwwpGBwSmfZqqPPPPwzmfqZq +VlRLvVjCJLnlpvvRdllLcJJWDHgMMHDDHtWFFDDQgH +SsSdrndpDlCdLftd +VGPVJgmQrVGHHZfwLlfCTmfwlDlT +PcJHcGgcWWbJpjRrphRbFpRn +PdPSMHMLzPPSShBdffMMzMRHQQrpppcqTCQQpCccTGTRCnCQ +vsbWmFbmJmZFFsmsbfpGVrGnWrrpVpnnVcTV +JZslstfZNNSSPdlSMwlM +bLLzRzZLbRqJJrDGGVZdwssDvGQw +FCtNJlTFtmPfldSvDvQFVVsjSv +PmCPHBhhPpWLWgzgHJ +qwmwFHCgPgPPqPwMCrHHFBVVRBttVRRffVfmsjVNNB +WSvcSnvbSWbhcbjlQbvlSQhlfBGcspVVsVGfVscpzpNcpBtN +hJSLhlvlTjPFHMLCCq +bggDpTggncGVVWbQcG +sRvSwwwFBSpFzvRvMFZqmPmMVqmcmPPVqhqqWq +SRBBrFZZwrddBFRjlptnLgDnTggdtd +PPfMcZMflbMQcMllPVfTVMwjWWmZvpWWpWhhjjpdWWww +sDQNnzsnQgDNsFzFqtGjGmWWSpWrGhdpvphdSW +nNQNqLBHLqzDnHgnVJfPJPCRBbfCcJlT +fppppWsjcSDPjjDpGhgwbfTgHTCbHJwbHbTR +rLBdQnvMNMmFPbLqHqTqgLHCgL +nrFznvMNMQdttrBcScsDstWcPGtWSc +lclnRSDnGZtvSwnZDZzhLffqdsCNwTBCBBdNsd +mPjmjmrFFpmQjMJQjlNdlhCsCLsTlNLs +ggmrHHVVQVPJpWrgpWScRvzZzGGRnZvlgzZn +GjGJGQJGcMTVfFDQzNVQzP +mHqdbmmdnJqVzVhRVNzPbR +wStmHJsJsLZLjTvM +QssMbVGdMQjZPjwVwHVZPZClllvgSgvlTgwwSSCgSCtC +WmmFBmJrcFRBFrJJBFchzWCStgCTgvhvTlfsNqfTlvTv +sFzzssDLzrBPjDVVddHMQD +fztDZSGrNrlnbnPTgFFpln +jvvQMMcLcjJmQwHdJvjQJnnbTbRFRphnnpsWgmFRPR +vTLHHCQLHBBjJCSZrVCZtSfSfrft +gHfHffHLjwHrRjLrLRZVMnTdTBsNTBwTVBsBnN +DWPhqhhDhvSGvWPzSzMBQBQVMMBBmvssvQvQ +CDGbqCDbChSbWGrHcHRgbcVcfrLJ +frlTLmtllbbbdpJS +qFjhzjThjHTFGHTjqhhjMzBhVpVpdbBnSJQRpBnVVdbRRQJd +vjWPWjWPPPWgwmfCrNvTvZ \ No newline at end of file diff --git a/day03/problem.md b/day03/problem.md new file mode 100644 index 0000000..aab03f9 --- /dev/null +++ b/day03/problem.md @@ -0,0 +1,67 @@ +--- Day 3: Rucksack Reorganization --- +One Elf has the important job of loading all of the rucksacks with supplies for the jungle journey. Unfortunately, that Elf didn't quite follow the packing instructions, and so a few items now need to be rearranged. + +Each rucksack has two large compartments. All items of a given type are meant to go into exactly one of the two compartments. The Elf that did the packing failed to follow this rule for exactly one item type per rucksack. + +The Elves have made a list of all of the items currently in each rucksack (your puzzle input), but they need your help finding the errors. Every item type is identified by a single lowercase or uppercase letter (that is, a and A refer to different types of items). + +The list of items for each rucksack is given as characters all on a single line. A given rucksack always has the same number of items in each of its two compartments, so the first half of the characters represent items in the first compartment, while the second half of the characters represent items in the second compartment. + +For example, suppose you have the following list of contents from six rucksacks: + +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw +The first rucksack contains the items vJrwpWtwJgWrhcsFMMfFFhFp, which means its first compartment contains the items vJrwpWtwJgWr, while the second compartment contains the items hcsFMMfFFhFp. The only item type that appears in both compartments is lowercase p. +The second rucksack's compartments contain jqHRNqRjqzjGDLGL and rsFMfFZSrLrFZsSL. The only item type that appears in both compartments is uppercase L. +The third rucksack's compartments contain PmmdzqPrV and vPwwTWBwg; the only common item type is uppercase P. +The fourth rucksack's compartments only share item type v. +The fifth rucksack's compartments only share item type t. +The sixth rucksack's compartments only share item type s. +To help prioritize item rearrangement, every item type can be converted to a priority: + +Lowercase item types a through z have priorities 1 through 26. +Uppercase item types A through Z have priorities 27 through 52. +In the above example, the priority of the item type that appears in both compartments of each rucksack is 16 (p), 38 (L), 42 (P), 22 (v), 20 (t), and 19 (s); the sum of these is 157. + +Find the item type that appears in both compartments of each rucksack. What is the sum of the priorities of those item types? + +Your puzzle answer was 8153. + +--- Part Two --- +As you finish identifying the misplaced items, the Elves come to you with another issue. + +For safety, the Elves are divided into groups of three. Every Elf carries a badge that identifies their group. For efficiency, within each group of three Elves, the badge is the only item type carried by all three Elves. That is, if a group's badge is item type B, then all three Elves will have item type B somewhere in their rucksack, and at most two of the Elves will be carrying any other item type. + +The problem is that someone forgot to put this year's updated authenticity sticker on the badges. All of the badges need to be pulled out of the rucksacks so the new authenticity stickers can be attached. + +Additionally, nobody wrote down which item type corresponds to each group's badges. The only way to tell which item type is the right one is by finding the one item type that is common between all three Elves in each group. + +Every set of three lines in your list corresponds to a single group, but each group can have a different badge item type. So, in the above example, the first group's rucksacks are the first three lines: + +vJrwpWtwJgWrhcsFMMfFFhFp +jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL +PmmdzqPrVvPwwTWBwg +And the second group's rucksacks are the next three lines: + +wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn +ttgJtRGJQctTZtZT +CrZsJsPPZsGzwwsLwLmpwMDw +In the first group, the only item type that appears in all three rucksacks is lowercase r; this must be their badges. In the second group, their badge item type must be Z. + +Priorities for these items must still be found to organize the sticker attachment efforts: here, they are 18 (r) for the first group and 52 (Z) for the second group. The sum of these is 70. + +Find the item type that corresponds to the badges of each three-Elf group. What is the sum of the priorities of those item types? + +Your puzzle answer was 2342. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day04/day04.test/UnitTestProblem.cs b/day04/day04.test/UnitTestProblem.cs new file mode 100644 index 0000000..638b2e0 --- /dev/null +++ b/day04/day04.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day04.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("2"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("4"); + } +} \ No newline at end of file diff --git a/day04/day04.test/Usings.cs b/day04/day04.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day04/day04.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day04/day04.test/day04.test.csproj b/day04/day04.test/day04.test.csproj new file mode 100644 index 0000000..f61400d --- /dev/null +++ b/day04/day04.test/day04.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day04/day04.test/testdata.txt b/day04/day04.test/testdata.txt new file mode 100644 index 0000000..99a66c5 --- /dev/null +++ b/day04/day04.test/testdata.txt @@ -0,0 +1,6 @@ +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 \ No newline at end of file diff --git a/day04/day04/Problem.cs b/day04/day04/Problem.cs new file mode 100644 index 0000000..d2ab894 --- /dev/null +++ b/day04/day04/Problem.cs @@ -0,0 +1,50 @@ +namespace day04; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var containCount = 0; + var overlapingCount = 0; + foreach (var line in lines) + { + var linesplit = line.Split(','); + var elf1 = linesplit[0]; + var rangeElf1 = elf1.Split('-'); + var start1 = int.Parse(rangeElf1[0]); + var end1 = int.Parse(rangeElf1[1]); + var elf2 = linesplit[1]; + var rangeElf2 = elf2.Split('-'); + var start2 = int.Parse(rangeElf2[0]); + var end2 = int.Parse(rangeElf2[1]); + //for problem 2 + if (start1 <= end2 && start2 <= end1) + { + overlapingCount++; + } + //for problem 1 + if ((start1 <= start2 && end2 <= end1) || + (start2 <= start1 && end1 <= end2)) + { + containCount++; + } + } + + // System.Console.WriteLine(containCount); + //513 + Result1 = containCount.ToString(); + + // System.Console.WriteLine(overlapingCount); + //878 + Result2 = overlapingCount.ToString(); + } + + public void ResolvePart2(string arg) + { + ResolvePart1(arg); + } +} \ No newline at end of file diff --git a/day04/day04/Program.cs b/day04/day04/Program.cs new file mode 100644 index 0000000..93af181 --- /dev/null +++ b/day04/day04/Program.cs @@ -0,0 +1,15 @@ +namespace day04; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day04/day04/day04.csproj b/day04/day04/day04.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day04/day04/day04.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day04/day04/input.txt b/day04/day04/input.txt new file mode 100644 index 0000000..1464d66 --- /dev/null +++ b/day04/day04/input.txt @@ -0,0 +1,1000 @@ +28-88,85-88 +9-70,18-18 +76-90,53-89 +17-86,11-17 +8-8,8-82 +16-85,15-95 +20-76,19-20 +56-57,57-66 +95-99,1-96 +14-17,17-67 +95-99,32-98 +30-99,29-98 +12-95,11-94 +3-82,1-72 +4-88,88-88 +2-10,11-59 +8-16,8-16 +22-95,23-94 +46-51,78-99 +61-99,62-94 +30-72,26-73 +6-93,2-92 +16-93,17-96 +1-99,2-88 +23-89,88-93 +30-73,3-73 +9-75,75-76 +75-97,70-99 +4-23,22-23 +5-94,4-4 +16-48,15-22 +10-62,61-97 +34-82,81-87 +16-98,15-99 +16-22,17-22 +20-40,21-58 +67-86,22-87 +6-73,6-33 +27-73,40-55 +57-98,58-97 +94-95,14-80 +16-90,91-91 +2-89,5-89 +17-95,96-96 +46-48,19-47 +50-59,51-60 +45-98,44-97 +99-99,6-97 +3-29,1-29 +26-48,25-49 +10-17,19-57 +28-57,28-56 +79-96,80-97 +5-78,4-25 +35-84,35-84 +24-99,20-98 +80-80,53-79 +88-97,12-88 +9-20,9-72 +75-78,35-54 +11-29,28-91 +48-74,49-75 +56-56,56-98 +41-69,33-42 +6-40,6-40 +49-80,49-79 +12-29,18-70 +19-20,13-80 +96-96,15-95 +5-99,4-4 +47-47,41-46 +53-82,65-85 +88-90,89-90 +12-12,12-88 +52-68,51-67 +1-80,2-81 +75-81,70-76 +35-58,35-57 +19-91,18-19 +18-73,72-74 +9-13,8-10 +5-40,35-37 +43-71,70-71 +24-24,25-43 +60-92,35-60 +43-52,47-53 +8-97,97-99 +57-89,57-89 +69-70,31-69 +48-49,48-79 +5-13,14-97 +9-95,9-83 +80-80,79-83 +30-77,29-78 +67-75,67-76 +20-67,21-87 +22-99,74-99 +12-12,11-96 +26-61,25-67 +19-48,47-91 +4-88,81-89 +75-96,74-97 +37-38,37-75 +3-3,4-76 +7-87,7-8 +1-99,2-99 +11-84,83-84 +71-95,69-95 +92-94,2-93 +7-95,21-95 +28-45,27-46 +16-24,16-63 +62-72,68-71 +36-96,90-98 +14-95,94-99 +26-67,25-55 +21-73,21-90 +35-44,34-43 +48-65,48-65 +80-89,80-99 +3-45,44-44 +27-86,67-85 +4-58,4-58 +12-38,11-39 +61-83,82-83 +4-86,4-85 +40-58,10-41 +8-9,8-98 +70-71,12-70 +40-40,40-78 +4-38,17-39 +5-23,22-94 +43-82,47-83 +32-74,86-96 +5-91,90-97 +10-93,11-86 +82-83,44-82 +61-69,57-68 +31-95,30-32 +42-59,42-98 +11-91,9-92 +42-81,19-63 +71-74,72-87 +88-89,6-88 +83-83,21-75 +50-61,59-62 +95-98,25-57 +13-17,16-87 +4-24,3-23 +4-56,3-5 +51-86,50-87 +49-55,30-56 +8-86,8-85 +3-99,3-3 +10-16,10-19 +6-96,5-95 +1-82,17-69 +35-62,35-55 +32-82,83-83 +9-76,75-75 +1-2,3-99 +86-94,93-99 +41-89,47-89 +2-60,3-61 +21-27,18-29 +5-6,6-54 +13-99,13-76 +71-71,34-70 +29-77,29-77 +7-83,6-64 +22-84,12-21 +93-97,15-94 +94-94,7-89 +24-94,32-99 +31-67,43-67 +46-61,46-60 +11-61,58-60 +5-58,5-5 +30-97,30-97 +65-83,82-83 +96-99,3-97 +11-97,6-12 +38-86,39-87 +24-24,24-66 +98-98,43-99 +5-32,29-33 +22-60,22-60 +9-72,71-71 +4-6,5-86 +27-30,31-94 +47-93,48-94 +1-2,5-91 +14-87,87-87 +26-75,25-96 +9-93,13-70 +6-10,9-95 +11-14,13-87 +69-71,2-69 +89-97,77-96 +5-16,4-14 +31-99,31-99 +30-39,33-88 +16-96,10-99 +20-74,19-73 +71-89,17-90 +50-51,26-50 +50-97,51-98 +4-84,4-84 +71-79,60-96 +39-83,81-82 +87-88,10-88 +93-99,68-99 +22-98,23-89 +12-96,13-97 +12-85,13-83 +3-97,3-98 +30-52,29-52 +11-96,97-97 +76-96,45-91 +22-97,23-98 +1-97,96-96 +4-83,5-84 +7-61,60-87 +62-66,37-61 +83-87,54-93 +40-74,7-40 +56-62,48-63 +88-94,57-89 +91-94,58-75 +1-88,87-87 +33-35,26-38 +9-10,9-94 +13-30,29-97 +95-95,23-95 +5-54,54-61 +16-73,72-73 +28-99,29-29 +32-91,33-90 +17-73,18-72 +20-34,13-20 +7-74,8-8 +43-58,42-59 +35-93,96-98 +31-71,62-89 +7-86,6-87 +37-78,38-79 +10-88,9-89 +5-94,20-94 +82-91,83-99 +14-34,4-14 +13-13,12-72 +1-98,16-98 +6-33,33-72 +35-83,36-36 +95-98,34-96 +23-23,22-68 +37-94,37-94 +42-97,96-99 +11-78,2-5 +23-88,87-87 +42-78,41-77 +58-74,58-78 +15-97,15-16 +3-11,5-83 +91-92,47-92 +63-96,62-99 +40-72,9-71 +64-89,37-69 +53-99,98-98 +28-33,26-34 +89-97,14-95 +16-93,92-97 +5-53,52-79 +52-52,53-96 +25-32,26-31 +35-73,35-74 +10-91,4-13 +2-28,5-28 +87-88,22-88 +31-76,32-75 +82-84,7-83 +38-61,60-60 +3-17,2-18 +74-93,4-94 +4-72,18-71 +69-71,19-70 +26-94,4-95 +44-77,52-78 +32-79,31-80 +45-79,23-46 +11-85,10-84 +75-95,19-76 +5-76,5-6 +60-71,65-70 +53-61,52-82 +4-4,5-95 +6-91,90-98 +45-92,46-92 +20-97,10-84 +21-45,31-46 +67-69,43-68 +49-70,12-70 +85-96,96-97 +7-77,8-69 +44-77,77-78 +13-86,85-85 +17-17,17-37 +77-79,13-78 +4-38,5-87 +22-23,23-47 +78-87,30-87 +12-20,1-11 +47-56,46-54 +3-52,1-2 +3-95,2-3 +9-40,8-13 +81-98,18-94 +42-69,38-89 +8-23,24-24 +16-73,15-17 +92-92,18-92 +3-78,78-79 +2-34,35-35 +19-61,60-83 +3-81,81-82 +7-61,6-40 +15-84,1-16 +52-70,30-69 +15-41,14-40 +32-73,32-74 +24-28,27-54 +2-98,18-98 +85-85,15-86 +1-88,2-88 +45-84,46-83 +20-26,34-52 +40-60,19-43 +51-81,80-81 +58-79,57-91 +12-52,28-38 +18-57,19-96 +4-99,2-3 +99-99,5-99 +52-75,53-53 +24-96,24-95 +9-93,10-87 +77-93,7-78 +17-81,18-80 +1-2,4-42 +24-47,46-73 +57-58,50-58 +21-58,21-82 +31-65,3-65 +5-10,3-8 +55-97,94-96 +31-40,30-34 +18-37,36-94 +18-88,17-27 +57-65,58-64 +55-56,55-56 +12-87,12-88 +69-98,14-52 +53-61,20-52 +40-62,16-63 +1-97,98-98 +2-84,1-2 +8-55,7-56 +91-91,91-92 +5-95,5-95 +9-17,2-16 +73-73,72-91 +44-88,5-87 +47-83,48-82 +1-23,22-83 +11-84,12-86 +90-93,5-92 +63-75,7-70 +60-89,89-90 +2-93,93-93 +14-60,13-28 +36-89,36-36 +49-99,4-97 +15-42,15-41 +12-90,90-91 +71-96,99-99 +37-37,37-70 +40-72,39-73 +25-60,26-59 +49-94,49-49 +20-80,21-81 +11-29,24-54 +12-88,55-89 +9-71,8-70 +4-69,5-68 +37-72,48-73 +26-98,27-58 +85-91,13-95 +8-41,8-8 +56-98,30-55 +21-92,20-97 +33-99,3-32 +1-61,3-94 +15-98,14-97 +60-99,59-61 +54-82,53-91 +21-33,17-41 +74-97,75-96 +10-51,52-52 +5-70,4-69 +41-93,42-92 +6-96,7-97 +17-28,2-27 +17-83,6-11 +53-99,54-96 +5-5,4-80 +36-81,53-72 +60-77,65-94 +44-87,87-88 +19-93,19-20 +63-80,43-70 +15-46,14-45 +61-78,77-78 +79-94,70-95 +20-41,20-20 +4-11,4-10 +10-98,4-10 +94-95,67-90 +9-56,10-10 +4-93,3-94 +49-59,49-83 +10-94,11-90 +20-21,20-92 +19-95,17-62 +1-95,69-96 +6-91,49-90 +12-98,11-99 +56-89,56-80 +42-96,42-97 +41-92,13-52 +78-94,57-86 +2-82,2-81 +1-1,1-60 +17-71,71-96 +10-88,9-34 +17-17,17-18 +35-99,34-90 +8-97,8-35 +73-85,74-85 +3-56,47-55 +1-4,3-76 +66-93,66-93 +27-27,26-66 +6-79,27-80 +49-89,48-89 +60-99,83-95 +64-64,48-64 +63-64,57-65 +15-17,30-95 +59-62,59-66 +4-29,5-99 +52-72,70-70 +5-91,1-98 +16-19,16-34 +35-35,1-34 +33-85,28-89 +7-78,6-79 +36-79,10-35 +52-74,51-75 +45-77,47-95 +26-26,26-93 +1-3,3-93 +69-88,8-69 +63-64,14-63 +46-46,45-88 +11-37,12-18 +5-92,6-91 +67-68,68-69 +31-89,32-32 +49-89,50-90 +3-4,4-94 +1-96,2-86 +6-91,7-90 +77-78,8-78 +38-76,38-77 +2-98,97-99 +43-48,48-71 +12-76,11-77 +25-40,25-41 +16-55,15-55 +1-91,2-91 +42-82,42-42 +32-90,31-33 +13-98,13-97 +18-80,18-65 +92-97,7-78 +1-3,2-69 +3-88,2-89 +6-94,7-67 +22-98,5-97 +24-32,33-96 +5-70,83-93 +1-61,60-61 +1-99,78-96 +88-98,4-89 +95-97,50-96 +56-93,55-97 +13-76,52-65 +86-87,40-87 +35-62,34-69 +26-44,27-60 +47-66,65-66 +2-97,1-87 +1-96,3-85 +13-82,16-82 +25-85,3-86 +36-63,3-99 +12-98,97-99 +4-6,2-5 +38-67,65-67 +77-96,27-30 +15-95,14-14 +22-87,22-60 +12-19,12-81 +16-79,8-80 +34-94,3-93 +26-62,25-62 +9-91,8-9 +94-98,30-33 +14-68,68-91 +79-95,84-95 +92-95,93-96 +2-96,95-99 +25-58,9-57 +7-87,6-6 +44-84,43-83 +78-88,77-87 +67-70,61-71 +35-64,64-65 +40-40,5-39 +9-74,9-74 +70-81,82-82 +11-58,10-11 +2-13,13-83 +56-71,70-88 +4-8,7-94 +5-88,4-93 +40-88,39-88 +14-84,69-83 +5-30,29-30 +91-94,92-94 +4-73,2-45 +69-98,30-70 +44-72,73-73 +32-41,32-38 +76-81,68-81 +62-75,62-69 +23-36,35-69 +95-96,26-95 +15-89,14-64 +8-75,9-97 +15-17,14-58 +16-18,18-92 +57-77,58-76 +90-98,23-91 +1-97,96-96 +37-96,1-38 +8-99,9-53 +4-9,10-10 +11-27,11-22 +83-95,80-86 +88-90,54-89 +53-66,53-57 +14-14,15-90 +6-9,8-98 +6-99,32-93 +28-70,29-70 +6-64,64-98 +18-68,19-69 +16-42,16-43 +3-91,2-91 +1-95,2-94 +18-19,8-19 +2-99,9-97 +76-86,42-86 +83-94,25-84 +21-64,9-87 +89-95,29-90 +4-96,3-97 +20-96,19-20 +28-74,28-29 +19-22,22-93 +62-87,83-97 +72-73,23-73 +22-52,21-51 +39-39,39-98 +9-95,9-95 +53-95,66-95 +36-87,19-37 +86-87,34-86 +12-56,11-11 +48-97,47-81 +26-62,54-58 +21-63,22-64 +27-90,90-90 +54-70,64-68 +7-84,92-94 +15-35,35-57 +19-91,20-92 +99-99,78-95 +46-89,46-47 +8-68,9-57 +4-77,1-69 +21-36,35-58 +24-30,26-30 +50-90,91-91 +2-31,8-64 +3-98,98-98 +43-70,70-71 +24-79,25-78 +30-30,31-73 +7-10,11-90 +1-95,2-2 +70-82,82-93 +90-90,4-59 +2-82,2-68 +4-19,4-31 +33-68,10-39 +13-22,21-91 +24-67,24-25 +1-9,4-10 +3-3,2-50 +42-84,43-83 +23-84,62-83 +78-79,78-80 +30-58,30-58 +71-71,38-72 +35-43,46-82 +49-55,31-75 +22-98,22-99 +27-57,26-57 +24-24,24-77 +89-92,79-89 +70-95,10-93 +13-36,14-21 +13-98,80-97 +11-14,17-48 +59-92,59-92 +19-26,18-40 +6-32,7-31 +12-48,12-12 +22-87,23-98 +5-96,6-88 +3-85,1-4 +85-88,43-85 +19-89,20-81 +52-52,53-71 +87-96,14-88 +4-5,1-1 +8-79,7-78 +76-77,7-77 +67-99,68-98 +21-68,66-69 +93-94,91-95 +24-88,8-87 +10-52,19-53 +27-86,28-84 +35-95,36-94 +27-86,85-86 +30-31,31-57 +39-87,38-91 +92-92,16-93 +2-83,1-92 +74-74,73-73 +5-25,23-26 +11-12,12-73 +68-80,71-80 +67-92,66-91 +23-33,25-33 +46-77,34-47 +25-78,23-78 +95-97,53-96 +99-99,1-99 +42-43,43-89 +17-18,9-18 +7-48,48-55 +36-61,60-62 +45-82,82-94 +1-96,3-96 +33-66,34-65 +21-81,20-82 +74-76,15-75 +25-25,25-86 +10-79,94-96 +8-94,5-9 +16-89,8-93 +20-21,21-95 +48-94,49-74 +88-89,89-89 +24-60,25-91 +85-85,31-86 +4-82,4-41 +27-88,27-87 +18-94,17-95 +67-76,51-89 +13-49,26-48 +9-88,9-9 +41-86,42-85 +57-96,14-58 +95-95,11-92 +58-58,57-86 +23-93,12-15 +1-97,2-97 +22-22,8-22 +51-91,50-90 +7-25,51-92 +74-88,73-87 +3-82,4-81 +89-98,67-90 +7-99,7-98 +26-62,31-71 +32-88,32-88 +14-65,46-64 +56-82,81-82 +54-64,53-65 +4-85,5-5 +85-86,3-85 +7-58,1-8 +4-82,5-56 +47-92,48-75 +27-79,28-80 +7-34,8-94 +35-40,35-46 +84-94,80-95 +83-99,84-98 +10-81,11-73 +5-91,20-23 +1-2,2-99 +50-50,9-51 +5-78,4-79 +9-99,61-98 +79-79,61-78 +13-20,14-20 +8-93,7-92 +3-27,3-99 +28-66,29-65 +15-97,14-99 +31-43,42-67 +53-57,54-56 +11-89,88-93 +77-82,78-78 +4-99,4-99 +16-75,12-14 +17-52,33-51 +8-83,41-55 +48-90,44-49 +1-4,3-72 +25-91,91-92 +3-10,4-9 +32-98,8-94 +32-33,1-33 +33-43,14-42 +23-83,24-83 +30-31,31-49 +7-84,84-85 +26-50,49-65 +73-85,46-92 +85-86,13-39 +7-78,7-75 +32-93,26-26 +59-96,5-97 +48-99,48-79 +21-24,21-25 +58-95,99-99 +26-27,22-26 +19-19,3-99 +46-97,46-96 +2-3,2-99 +26-92,6-21 +1-99,1-2 +22-31,31-81 +10-65,9-86 +1-99,2-98 +13-78,13-79 +96-96,54-96 +8-94,7-23 +1-97,96-99 +28-70,27-71 +37-95,37-94 +9-90,4-89 +9-92,10-93 +8-80,86-94 +2-2,4-9 +6-41,6-41 +25-76,24-77 +95-98,85-95 +4-82,1-2 +56-73,56-84 +2-99,20-99 +14-17,17-91 +56-74,55-75 +45-97,99-99 +56-56,16-55 +43-93,44-86 +61-84,25-83 +82-99,5-83 +19-37,3-18 +42-42,4-42 +34-41,35-78 +12-79,11-80 +3-72,4-71 +16-99,23-85 +21-46,47-47 +33-65,33-33 +36-57,36-58 +5-82,82-83 +2-95,1-95 +1-37,5-31 +70-70,7-69 +17-86,18-87 +17-91,44-91 +73-88,73-89 +40-89,39-92 +68-97,91-96 +25-97,7-96 +36-83,37-83 +70-74,30-63 +56-93,57-93 +98-99,58-99 +15-95,94-97 +26-40,40-41 +3-99,2-44 +20-32,31-31 +57-97,56-57 +38-61,17-37 +13-62,12-63 +60-76,21-78 +57-66,56-67 +60-97,77-98 +43-68,42-43 +23-56,23-79 +34-44,35-44 +39-74,38-90 +3-84,2-85 +3-31,4-99 +74-85,73-85 +11-19,18-79 +25-25,26-64 +86-91,93-94 +16-95,15-92 +64-71,63-69 +45-45,35-44 +94-97,17-92 +29-97,28-98 +67-71,20-71 +7-86,7-85 +14-45,22-39 +6-66,6-19 +44-93,94-94 +52-62,52-61 +3-3,4-71 +22-80,21-81 +35-98,35-98 +37-44,38-43 +50-64,50-54 +50-99,51-99 +9-24,10-23 +24-24,23-86 +24-72,25-72 +33-61,49-62 +35-72,73-77 +78-79,79-96 +30-30,30-58 +58-76,36-75 +34-69,35-68 +7-91,5-6 +1-91,1-91 +2-2,2-99 +46-78,40-46 +7-78,6-79 +54-70,4-32 +63-76,5-77 +15-60,59-86 +1-75,69-75 +4-66,67-67 +15-99,15-95 +10-17,2-53 +2-46,18-61 +71-71,48-71 +19-98,14-99 +12-48,11-31 +30-30,30-98 +63-92,6-64 +21-94,95-95 +13-66,65-67 +7-11,14-79 +18-18,16-17 +11-45,91-97 +26-34,25-34 +40-60,4-81 +19-69,18-68 +34-79,99-99 +29-39,25-57 +2-98,98-98 +96-99,47-96 +6-45,9-45 +1-11,10-85 +6-77,5-76 +68-79,68-79 +45-55,46-49 +66-69,68-70 +14-80,20-77 +25-69,31-70 +16-53,15-54 +56-99,56-99 +45-47,32-46 +50-63,44-62 +18-75,29-76 +11-11,12-31 +19-91,90-91 +16-95,17-96 +19-95,19-94 +20-95,19-20 +17-96,16-95 +13-16,13-78 +50-62,34-63 +80-99,81-98 +13-81,83-96 +92-98,42-93 +38-89,57-89 +62-65,66-88 +54-85,55-85 +17-87,16-17 +3-6,6-74 +5-99,6-98 +22-41,73-73 +14-78,12-78 +35-51,34-47 +94-94,15-94 +58-75,13-71 +20-51,18-21 +31-60,30-96 +29-89,28-95 +39-40,40-82 +14-85,17-84 +27-57,26-94 +24-91,23-24 +8-72,71-76 +49-69,6-69 +28-28,29-52 +25-88,54-87 +89-90,16-90 +28-99,28-30 +17-17,17-88 +19-67,68-77 +64-64,34-65 +3-97,22-98 +17-98,16-97 +30-89,91-97 +13-30,14-31 +1-4,3-97 +2-93,1-98 +13-83,13-83 +80-90,80-91 +7-10,3-9 +65-79,70-80 +24-92,24-93 +16-94,43-81 +33-86,62-85 +53-78,79-79 +3-70,69-99 +95-95,16-96 +41-69,42-74 +83-83,51-82 +2-39,3-39 +6-15,5-16 +6-49,6-49 +57-95,95-96 +7-78,6-99 +78-83,81-99 +41-99,7-98 +1-98,2-97 +41-90,23-42 +9-61,9-24 +13-79,40-55 +4-13,10-18 +51-55,50-77 +87-90,86-91 +15-16,15-96 +19-29,20-28 +46-46,47-49 +9-82,7-7 +12-55,6-20 +4-41,4-41 +1-94,66-93 +4-91,4-92 +7-61,21-91 +7-90,38-91 +12-32,32-35 +6-94,93-94 +6-7,7-7 \ No newline at end of file diff --git a/day04/problem.md b/day04/problem.md new file mode 100644 index 0000000..3501eb6 --- /dev/null +++ b/day04/problem.md @@ -0,0 +1,65 @@ +--- Day 4: Camp Cleanup --- +Space needs to be cleared before the last supplies can be unloaded from the ships, and so several Elves have been assigned the job of cleaning up sections of the camp. Every section has a unique ID number, and each Elf is assigned a range of section IDs. + +However, as some of the Elves compare their section assignments with each other, they've noticed that many of the assignments overlap. To try to quickly find overlaps and reduce duplicated effort, the Elves pair up and make a big list of the section assignments for each pair (your puzzle input). + +For example, consider the following list of section assignment pairs: + +2-4,6-8 +2-3,4-5 +5-7,7-9 +2-8,3-7 +6-6,4-6 +2-6,4-8 +For the first few pairs, this list means: + +Within the first pair of Elves, the first Elf was assigned sections 2-4 (sections 2, 3, and 4), while the second Elf was assigned sections 6-8 (sections 6, 7, 8). +The Elves in the second pair were each assigned two sections. +The Elves in the third pair were each assigned three sections: one got sections 5, 6, and 7, while the other also got 7, plus 8 and 9. +This example list uses single-digit section IDs to make it easier to draw; your actual list might contain larger numbers. Visually, these pairs of section assignments look like this: + +.234..... 2-4 +.....678. 6-8 + +.23...... 2-3 +...45.... 4-5 + +....567.. 5-7 +......789 7-9 + +.2345678. 2-8 +..34567.. 3-7 + +.....6... 6-6 +...456... 4-6 + +.23456... 2-6 +...45678. 4-8 +Some of the pairs have noticed that one of their assignments fully contains the other. For example, 2-8 fully contains 3-7, and 6-6 is fully contained by 4-6. In pairs where one assignment fully contains the other, one Elf in the pair would be exclusively cleaning sections their partner will already be cleaning, so these seem like the most in need of reconsideration. In this example, there are 2 such pairs. + +In how many assignment pairs does one range fully contain the other? + +Your puzzle answer was 513. + +--- Part Two --- +It seems like there is still quite a bit of duplicate work planned. Instead, the Elves would like to know the number of pairs that overlap at all. + +In the above example, the first two pairs (2-4,6-8 and 2-3,4-5) don't overlap, while the remaining four pairs (5-7,7-9, 2-8,3-7, 6-6,4-6, and 2-6,4-8) do overlap: + +5-7,7-9 overlaps in a single section, 7. +2-8,3-7 overlaps all of the sections 3 through 7. +6-6,4-6 overlaps in a single section, 6. +2-6,4-8 overlaps in sections 4, 5, and 6. +So, in this example, the number of overlapping assignment pairs is 4. + +In how many assignment pairs do the ranges overlap? + +Your puzzle answer was 878. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day05/day05.test/UnitTestProblem.cs b/day05/day05.test/UnitTestProblem.cs new file mode 100644 index 0000000..731fa9a --- /dev/null +++ b/day05/day05.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day05.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("CMZ"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("MCD"); + } +} \ No newline at end of file diff --git a/day05/day05.test/Usings.cs b/day05/day05.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day05/day05.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day05/day05.test/day05.test.csproj b/day05/day05.test/day05.test.csproj new file mode 100644 index 0000000..fc60ca0 --- /dev/null +++ b/day05/day05.test/day05.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day05/day05.test/testdata.txt b/day05/day05.test/testdata.txt new file mode 100644 index 0000000..e98aba4 --- /dev/null +++ b/day05/day05.test/testdata.txt @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 \ No newline at end of file diff --git a/day05/day05/Problem.cs b/day05/day05/Problem.cs new file mode 100644 index 0000000..9e8054e --- /dev/null +++ b/day05/day05/Problem.cs @@ -0,0 +1,140 @@ +namespace day05; +using System.Text.RegularExpressions; + +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var baseStackLine = lines.First(x => x.Contains("1")); + var idxBaseLine = Array.IndexOf(lines, baseStackLine); + // System.Console.WriteLine($"idxBaseLine: {idxBaseLine}"); + + var noStacks = int.Parse(lines[idxBaseLine].Split(' ', StringSplitOptions.RemoveEmptyEntries).Last()); + // System.Console.WriteLine($"noStacks: {noStacks}"); + + List> listOfStacks = new List>(); + for (int j = 0; j < noStacks; j++) + { + listOfStacks.Add(new Stack()); + } + for (int i = idxBaseLine - 1; i >= 0; i--) + { + var line = lines[i]; + // System.Console.WriteLine($"i: {i} - {line}"); + for (int j = 0; j < noStacks; j++) + { + var crateLetter = line[j * 4 + 1].ToString(); + if (!string.IsNullOrWhiteSpace(crateLetter)) + { + listOfStacks[j].Push(crateLetter); + } + } + } + + var firstMoveLine = lines.First(x => x.Contains("move")); + var idxFirstModeLine = Array.IndexOf(lines, firstMoveLine); + // System.Console.WriteLine($"idxFirstModeLine: {idxFirstModeLine}"); + + for (int i = idxFirstModeLine; i < lines.Length; i++) + { + var moveLine = lines[i]; + Regex rg = new Regex("move (?[0-9]+) from (?[0-9]+) to (?[0-9]+)"); + var match = rg.Match(moveLine); + if (match.Success) + { + var pieces = int.Parse(match.Groups["pieces"].Captures[0].Value); + var from = int.Parse(match.Groups["from"].Captures[0].Value); + var to = int.Parse(match.Groups["to"].Captures[0].Value); + // System.Console.WriteLine($"pieces: {pieces} from: {from} to: {to}"); + + var fromStack = listOfStacks[from - 1]; + var toStack = listOfStacks[to - 1]; + var movingStack = new Stack(); + for (int idxPieces = 0; idxPieces < pieces; idxPieces++) + { + var elementToMove = fromStack.Pop(); + movingStack.Push(elementToMove); + toStack.Push(elementToMove); + } + } + } + + var final = string.Join("", listOfStacks.Select(s => s.First()).ToArray()); + // System.Console.WriteLine($"final: {final}"); + // NTWZZWHFV + Result1 = final.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var baseStackLine = lines.First(x => x.Contains("1")); + var idxBaseLine = Array.IndexOf(lines, baseStackLine); + // System.Console.WriteLine($"idxBaseLine: {idxBaseLine}"); + + var noStacks = int.Parse(lines[idxBaseLine].Split(' ', StringSplitOptions.RemoveEmptyEntries).Last()); + // System.Console.WriteLine($"noStacks: {noStacks}"); + + List> listOfStacks = new List>(); + for (int j = 0; j < noStacks; j++) + { + listOfStacks.Add(new Stack()); + } + for (int i = idxBaseLine - 1; i >= 0; i--) + { + var line = lines[i]; + // System.Console.WriteLine($"i: {i} - {line}"); + for (int j = 0; j < noStacks; j++) + { + var crateLetter = line[j * 4 + 1].ToString(); + if (!string.IsNullOrWhiteSpace(crateLetter)) + { + listOfStacks[j].Push(crateLetter); + } + } + } + + var firstMoveLine = lines.First(x => x.Contains("move")); + var idxFirstModeLine = Array.IndexOf(lines, firstMoveLine); + // System.Console.WriteLine($"idxFirstModeLine: {idxFirstModeLine}"); + + for (int i = idxFirstModeLine; i < lines.Length; i++) + { + var moveLine = lines[i]; + Regex rg = new Regex("move (?[0-9]+) from (?[0-9]+) to (?[0-9]+)"); + var match = rg.Match(moveLine); + if (match.Success) + { + var pieces = int.Parse(match.Groups["pieces"].Captures[0].Value); + var from = int.Parse(match.Groups["from"].Captures[0].Value); + var to = int.Parse(match.Groups["to"].Captures[0].Value); + // System.Console.WriteLine($"pieces: {pieces} from: {from} to: {to}"); + + var fromStack = listOfStacks[from - 1]; + var toStack = listOfStacks[to - 1]; + var movingStack = new Stack(); + for (int idxPieces = 0; idxPieces < pieces; idxPieces++) + { + var elementToMove = fromStack.Pop(); + movingStack.Push(elementToMove); + } + while (movingStack.Count > 0) + { + var elementToMove = movingStack.Pop(); + toStack.Push(elementToMove); + } + } + } + + var final = string.Join("", listOfStacks.Select(s => s.First()).ToArray()); + // System.Console.WriteLine($"final: {final}"); + // BRZGFVBTJ + Result2 = final.ToString(); + } +} \ No newline at end of file diff --git a/day05/day05/Program.cs b/day05/day05/Program.cs new file mode 100644 index 0000000..64651f4 --- /dev/null +++ b/day05/day05/Program.cs @@ -0,0 +1,16 @@ +namespace day05; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day05/day05/day05.csproj b/day05/day05/day05.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day05/day05/day05.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day05/day05/input.txt b/day05/day05/input.txt new file mode 100644 index 0000000..5c2c7e9 --- /dev/null +++ b/day05/day05/input.txt @@ -0,0 +1,512 @@ + [M] [W] [M] + [L] [Q] [S] [C] [R] + [Q] [F] [F] [T] [N] [S] + [N] [V] [V] [H] [L] [J] [D] + [D] [D] [W] [P] [G] [R] [D] [F] +[T] [T] [M] [G] [G] [Q] [N] [W] [L] +[Z] [H] [F] [J] [D] [Z] [S] [H] [Q] +[B] [V] [B] [T] [W] [V] [Z] [Z] [M] + 1 2 3 4 5 6 7 8 9 + +move 1 from 7 to 4 +move 1 from 6 to 2 +move 5 from 9 to 4 +move 2 from 2 to 8 +move 2 from 2 to 6 +move 3 from 3 to 7 +move 3 from 7 to 1 +move 1 from 9 to 4 +move 4 from 7 to 3 +move 5 from 1 to 8 +move 1 from 1 to 2 +move 1 from 4 to 9 +move 4 from 5 to 6 +move 1 from 5 to 8 +move 3 from 2 to 4 +move 3 from 6 to 4 +move 3 from 5 to 9 +move 1 from 9 to 7 +move 1 from 9 to 8 +move 2 from 7 to 9 +move 1 from 7 to 9 +move 1 from 7 to 8 +move 2 from 9 to 8 +move 13 from 4 to 2 +move 2 from 6 to 1 +move 3 from 3 to 2 +move 9 from 2 to 7 +move 1 from 9 to 7 +move 5 from 7 to 8 +move 9 from 8 to 4 +move 2 from 7 to 1 +move 1 from 1 to 7 +move 2 from 3 to 2 +move 14 from 4 to 5 +move 3 from 8 to 4 +move 13 from 8 to 3 +move 2 from 7 to 1 +move 6 from 6 to 5 +move 1 from 6 to 9 +move 3 from 2 to 8 +move 1 from 7 to 8 +move 5 from 2 to 8 +move 4 from 4 to 8 +move 1 from 9 to 8 +move 1 from 7 to 1 +move 1 from 1 to 2 +move 7 from 3 to 2 +move 4 from 3 to 2 +move 2 from 5 to 3 +move 2 from 1 to 5 +move 5 from 8 to 7 +move 6 from 8 to 3 +move 11 from 5 to 8 +move 8 from 8 to 9 +move 5 from 7 to 8 +move 3 from 1 to 8 +move 5 from 3 to 8 +move 11 from 2 to 9 +move 1 from 3 to 5 +move 1 from 2 to 1 +move 1 from 2 to 7 +move 6 from 5 to 7 +move 19 from 9 to 7 +move 3 from 5 to 3 +move 1 from 5 to 4 +move 1 from 1 to 4 +move 1 from 9 to 8 +move 25 from 7 to 9 +move 2 from 4 to 1 +move 2 from 1 to 4 +move 2 from 4 to 7 +move 2 from 7 to 9 +move 5 from 3 to 1 +move 1 from 7 to 1 +move 9 from 9 to 5 +move 3 from 5 to 6 +move 9 from 9 to 1 +move 7 from 1 to 3 +move 6 from 8 to 9 +move 1 from 5 to 2 +move 10 from 9 to 2 +move 1 from 2 to 7 +move 5 from 9 to 8 +move 1 from 5 to 8 +move 5 from 3 to 8 +move 1 from 9 to 4 +move 4 from 3 to 6 +move 4 from 6 to 3 +move 3 from 1 to 4 +move 3 from 2 to 4 +move 3 from 5 to 8 +move 3 from 4 to 9 +move 1 from 7 to 3 +move 2 from 9 to 8 +move 4 from 2 to 5 +move 1 from 3 to 4 +move 1 from 9 to 3 +move 5 from 5 to 6 +move 7 from 8 to 5 +move 3 from 1 to 7 +move 6 from 5 to 8 +move 5 from 4 to 5 +move 3 from 3 to 2 +move 1 from 1 to 4 +move 19 from 8 to 1 +move 3 from 7 to 3 +move 4 from 2 to 9 +move 1 from 2 to 6 +move 7 from 6 to 4 +move 1 from 6 to 2 +move 2 from 1 to 3 +move 5 from 4 to 1 +move 1 from 6 to 2 +move 3 from 3 to 6 +move 12 from 1 to 2 +move 2 from 8 to 1 +move 14 from 2 to 4 +move 7 from 1 to 5 +move 10 from 4 to 6 +move 3 from 6 to 4 +move 1 from 8 to 4 +move 4 from 3 to 5 +move 1 from 2 to 3 +move 2 from 1 to 4 +move 17 from 5 to 3 +move 7 from 4 to 1 +move 1 from 9 to 4 +move 4 from 6 to 3 +move 5 from 4 to 8 +move 12 from 3 to 1 +move 6 from 3 to 5 +move 17 from 1 to 5 +move 2 from 1 to 9 +move 3 from 1 to 4 +move 7 from 8 to 2 +move 4 from 3 to 7 +move 1 from 1 to 8 +move 17 from 5 to 2 +move 11 from 2 to 8 +move 11 from 8 to 4 +move 11 from 2 to 4 +move 4 from 6 to 1 +move 4 from 1 to 3 +move 2 from 6 to 9 +move 3 from 7 to 8 +move 3 from 5 to 3 +move 23 from 4 to 3 +move 4 from 4 to 8 +move 1 from 7 to 4 +move 2 from 2 to 3 +move 6 from 3 to 2 +move 16 from 3 to 9 +move 2 from 5 to 8 +move 1 from 4 to 5 +move 2 from 5 to 9 +move 1 from 2 to 3 +move 1 from 3 to 8 +move 9 from 9 to 1 +move 6 from 3 to 8 +move 3 from 3 to 1 +move 18 from 8 to 9 +move 1 from 3 to 5 +move 5 from 1 to 4 +move 5 from 1 to 8 +move 3 from 4 to 1 +move 1 from 5 to 2 +move 2 from 4 to 8 +move 1 from 1 to 2 +move 5 from 2 to 7 +move 2 from 8 to 1 +move 2 from 2 to 6 +move 3 from 1 to 6 +move 3 from 9 to 6 +move 31 from 9 to 7 +move 26 from 7 to 8 +move 3 from 1 to 6 +move 22 from 8 to 4 +move 2 from 4 to 5 +move 4 from 6 to 5 +move 11 from 4 to 3 +move 9 from 4 to 6 +move 2 from 5 to 9 +move 4 from 7 to 1 +move 2 from 6 to 1 +move 1 from 5 to 3 +move 6 from 8 to 6 +move 8 from 6 to 2 +move 1 from 1 to 6 +move 3 from 1 to 3 +move 1 from 5 to 3 +move 1 from 5 to 9 +move 5 from 7 to 2 +move 2 from 9 to 6 +move 4 from 8 to 6 +move 1 from 7 to 2 +move 1 from 5 to 4 +move 12 from 3 to 4 +move 3 from 3 to 1 +move 3 from 6 to 8 +move 1 from 9 to 3 +move 6 from 2 to 6 +move 2 from 3 to 2 +move 10 from 2 to 7 +move 2 from 1 to 9 +move 2 from 1 to 6 +move 1 from 1 to 4 +move 9 from 7 to 9 +move 3 from 8 to 7 +move 7 from 4 to 8 +move 2 from 7 to 4 +move 4 from 8 to 1 +move 5 from 8 to 2 +move 3 from 1 to 3 +move 1 from 8 to 7 +move 3 from 3 to 7 +move 4 from 2 to 6 +move 8 from 4 to 2 +move 5 from 2 to 5 +move 11 from 9 to 7 +move 2 from 5 to 7 +move 16 from 7 to 8 +move 5 from 8 to 7 +move 1 from 4 to 3 +move 3 from 5 to 1 +move 11 from 6 to 5 +move 7 from 5 to 4 +move 5 from 7 to 4 +move 1 from 3 to 7 +move 2 from 5 to 4 +move 10 from 4 to 8 +move 14 from 6 to 3 +move 1 from 5 to 9 +move 1 from 6 to 5 +move 2 from 2 to 9 +move 2 from 1 to 3 +move 2 from 5 to 3 +move 2 from 7 to 6 +move 2 from 1 to 4 +move 1 from 2 to 3 +move 19 from 3 to 6 +move 3 from 9 to 2 +move 4 from 2 to 6 +move 6 from 6 to 7 +move 13 from 6 to 2 +move 14 from 8 to 1 +move 6 from 4 to 3 +move 5 from 7 to 8 +move 3 from 6 to 3 +move 2 from 8 to 2 +move 2 from 6 to 8 +move 4 from 1 to 8 +move 13 from 8 to 4 +move 10 from 4 to 7 +move 1 from 4 to 5 +move 1 from 5 to 1 +move 3 from 6 to 5 +move 3 from 8 to 9 +move 9 from 3 to 1 +move 3 from 5 to 8 +move 3 from 9 to 6 +move 3 from 8 to 7 +move 1 from 6 to 9 +move 1 from 9 to 4 +move 9 from 2 to 8 +move 2 from 2 to 6 +move 14 from 7 to 1 +move 31 from 1 to 5 +move 3 from 1 to 7 +move 4 from 6 to 8 +move 24 from 5 to 3 +move 2 from 8 to 1 +move 1 from 8 to 5 +move 2 from 1 to 7 +move 3 from 7 to 6 +move 6 from 8 to 6 +move 2 from 4 to 2 +move 1 from 4 to 3 +move 2 from 2 to 7 +move 6 from 6 to 7 +move 4 from 8 to 6 +move 7 from 6 to 2 +move 12 from 7 to 5 +move 4 from 2 to 8 +move 1 from 2 to 4 +move 1 from 4 to 6 +move 1 from 6 to 7 +move 1 from 7 to 3 +move 3 from 3 to 8 +move 17 from 3 to 5 +move 4 from 3 to 6 +move 35 from 5 to 3 +move 2 from 2 to 6 +move 1 from 5 to 9 +move 9 from 3 to 7 +move 6 from 8 to 1 +move 4 from 2 to 6 +move 4 from 6 to 9 +move 20 from 3 to 9 +move 22 from 9 to 7 +move 1 from 8 to 6 +move 29 from 7 to 5 +move 4 from 6 to 8 +move 6 from 1 to 8 +move 2 from 7 to 3 +move 1 from 6 to 5 +move 2 from 3 to 9 +move 1 from 9 to 3 +move 4 from 5 to 6 +move 18 from 5 to 1 +move 7 from 3 to 1 +move 1 from 3 to 6 +move 3 from 5 to 1 +move 1 from 3 to 9 +move 4 from 5 to 2 +move 10 from 8 to 7 +move 2 from 9 to 3 +move 1 from 3 to 5 +move 21 from 1 to 9 +move 1 from 3 to 2 +move 1 from 2 to 9 +move 15 from 9 to 3 +move 4 from 7 to 1 +move 2 from 6 to 1 +move 7 from 9 to 1 +move 1 from 5 to 4 +move 1 from 4 to 6 +move 6 from 3 to 9 +move 3 from 6 to 5 +move 19 from 1 to 6 +move 8 from 3 to 6 +move 1 from 3 to 7 +move 20 from 6 to 7 +move 1 from 2 to 6 +move 6 from 9 to 8 +move 2 from 9 to 4 +move 1 from 1 to 3 +move 1 from 2 to 9 +move 3 from 5 to 6 +move 2 from 7 to 3 +move 2 from 9 to 7 +move 1 from 4 to 8 +move 4 from 8 to 9 +move 4 from 7 to 1 +move 2 from 1 to 7 +move 1 from 3 to 2 +move 2 from 8 to 9 +move 6 from 6 to 2 +move 1 from 8 to 1 +move 1 from 5 to 7 +move 4 from 2 to 9 +move 1 from 3 to 5 +move 5 from 6 to 1 +move 1 from 4 to 2 +move 1 from 9 to 6 +move 1 from 9 to 6 +move 4 from 6 to 3 +move 7 from 9 to 7 +move 8 from 7 to 2 +move 1 from 5 to 8 +move 5 from 2 to 9 +move 3 from 2 to 5 +move 6 from 1 to 3 +move 17 from 7 to 6 +move 1 from 8 to 2 +move 2 from 1 to 7 +move 5 from 9 to 4 +move 4 from 3 to 8 +move 3 from 4 to 1 +move 1 from 9 to 2 +move 4 from 2 to 1 +move 1 from 8 to 4 +move 1 from 5 to 9 +move 1 from 2 to 3 +move 3 from 3 to 2 +move 10 from 7 to 6 +move 3 from 4 to 1 +move 5 from 3 to 2 +move 4 from 1 to 5 +move 3 from 8 to 6 +move 12 from 6 to 4 +move 1 from 9 to 3 +move 1 from 5 to 2 +move 3 from 1 to 6 +move 12 from 6 to 8 +move 3 from 1 to 5 +move 2 from 4 to 3 +move 5 from 8 to 7 +move 7 from 5 to 3 +move 3 from 7 to 9 +move 1 from 5 to 8 +move 5 from 3 to 7 +move 10 from 6 to 5 +move 2 from 7 to 5 +move 8 from 2 to 9 +move 5 from 3 to 9 +move 9 from 5 to 1 +move 5 from 7 to 4 +move 15 from 9 to 5 +move 1 from 2 to 5 +move 1 from 8 to 5 +move 6 from 4 to 1 +move 2 from 2 to 9 +move 18 from 5 to 8 +move 18 from 8 to 3 +move 16 from 3 to 4 +move 3 from 5 to 8 +move 1 from 9 to 2 +move 3 from 1 to 7 +move 3 from 8 to 2 +move 3 from 7 to 9 +move 2 from 3 to 4 +move 3 from 9 to 8 +move 11 from 1 to 6 +move 2 from 9 to 4 +move 3 from 6 to 9 +move 8 from 6 to 4 +move 26 from 4 to 7 +move 1 from 2 to 5 +move 1 from 5 to 2 +move 3 from 9 to 3 +move 21 from 7 to 6 +move 4 from 2 to 4 +move 1 from 2 to 3 +move 5 from 7 to 6 +move 8 from 8 to 1 +move 1 from 3 to 7 +move 9 from 1 to 4 +move 1 from 7 to 4 +move 20 from 4 to 7 +move 1 from 8 to 5 +move 2 from 4 to 8 +move 1 from 4 to 9 +move 3 from 8 to 9 +move 1 from 5 to 8 +move 2 from 3 to 1 +move 4 from 7 to 8 +move 3 from 7 to 5 +move 1 from 1 to 7 +move 4 from 8 to 3 +move 3 from 5 to 6 +move 1 from 8 to 4 +move 1 from 1 to 8 +move 28 from 6 to 4 +move 1 from 6 to 1 +move 2 from 7 to 8 +move 1 from 8 to 7 +move 1 from 8 to 1 +move 2 from 1 to 9 +move 3 from 9 to 3 +move 12 from 7 to 5 +move 7 from 3 to 1 +move 1 from 3 to 6 +move 26 from 4 to 9 +move 1 from 6 to 3 +move 1 from 3 to 6 +move 1 from 8 to 6 +move 1 from 7 to 8 +move 1 from 6 to 3 +move 3 from 1 to 3 +move 5 from 4 to 3 +move 28 from 9 to 4 +move 2 from 1 to 5 +move 22 from 4 to 1 +move 3 from 5 to 3 +move 5 from 5 to 7 +move 10 from 1 to 6 +move 1 from 5 to 2 +move 3 from 5 to 3 +move 2 from 5 to 9 +move 3 from 9 to 7 +move 2 from 4 to 5 +move 1 from 5 to 4 +move 4 from 3 to 8 +move 1 from 5 to 7 +move 9 from 6 to 5 +move 1 from 7 to 6 +move 1 from 6 to 5 +move 2 from 6 to 9 +move 3 from 5 to 1 +move 13 from 1 to 3 +move 7 from 7 to 5 +move 1 from 2 to 9 +move 3 from 8 to 2 +move 1 from 7 to 2 +move 3 from 4 to 3 +move 19 from 3 to 8 +move 5 from 3 to 7 +move 1 from 7 to 1 +move 19 from 8 to 6 +move 5 from 1 to 4 +move 5 from 5 to 2 +move 2 from 2 to 7 +move 3 from 4 to 1 +move 6 from 5 to 7 +move 2 from 8 to 7 +move 2 from 2 to 7 +move 3 from 3 to 5 +move 5 from 7 to 6 +move 6 from 6 to 1 +move 2 from 5 to 1 +move 2 from 4 to 3 +move 1 from 5 to 8 \ No newline at end of file diff --git a/day05/day05/testdata.txt b/day05/day05/testdata.txt new file mode 100644 index 0000000..e98aba4 --- /dev/null +++ b/day05/day05/testdata.txt @@ -0,0 +1,9 @@ + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 \ No newline at end of file diff --git a/day05/problem.md b/day05/problem.md new file mode 100644 index 0000000..3300b2c --- /dev/null +++ b/day05/problem.md @@ -0,0 +1,106 @@ +--- Day 5: Supply Stacks --- +The expedition can depart as soon as the final supplies have been unloaded from the ships. Supplies are stored in stacks of marked crates, but because the needed supplies are buried under many other crates, the crates need to be rearranged. + +The ship has a giant cargo crane capable of moving crates between stacks. To ensure none of the crates get crushed or fall over, the crane operator will rearrange them in a series of carefully-planned steps. After the crates are rearranged, the desired crates will be at the top of each stack. + +The Elves don't want to interrupt the crane operator during this delicate procedure, but they forgot to ask her which crate will end up where, and they want to be ready to unload them as soon as possible so they can embark. + +They do, however, have a drawing of the starting stacks of crates and the rearrangement procedure (your puzzle input). For example: + + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 + +move 1 from 2 to 1 +move 3 from 1 to 3 +move 2 from 2 to 1 +move 1 from 1 to 2 +In this example, there are three stacks of crates. Stack 1 contains two crates: crate Z is on the bottom, and crate N is on top. Stack 2 contains three crates; from bottom to top, they are crates M, C, and D. Finally, stack 3 contains a single crate, P. + +Then, the rearrangement procedure is given. In each step of the procedure, a quantity of crates is moved from one stack to a different stack. In the first step of the above rearrangement procedure, one crate is moved from stack 2 to stack 1, resulting in this configuration: + +[D] +[N] [C] +[Z] [M] [P] + 1 2 3 +In the second step, three crates are moved from stack 1 to stack 3. Crates are moved one at a time, so the first crate to be moved (D) ends up below the second and third crates: + + [Z] + [N] + [C] [D] + [M] [P] + 1 2 3 +Then, both crates are moved from stack 2 to stack 1. Again, because crates are moved one at a time, crate C ends up below crate M: + + [Z] + [N] +[M] [D] +[C] [P] + 1 2 3 +Finally, one crate is moved from stack 1 to stack 2: + + [Z] + [N] + [D] +[C] [M] [P] + 1 2 3 +The Elves just need to know which crate will end up on top of each stack; in this example, the top crates are C in stack 1, M in stack 2, and Z in stack 3, so you should combine these together and give the Elves the message CMZ. + +After the rearrangement procedure completes, what crate ends up on top of each stack? + +Your puzzle answer was NTWZZWHFV. + +--- Part Two --- +As you watch the crane operator expertly rearrange the crates, you notice the process isn't following your prediction. + +Some mud was covering the writing on the side of the crane, and you quickly wipe it away. The crane isn't a CrateMover 9000 - it's a CrateMover 9001. + +The CrateMover 9001 is notable for many new and exciting features: air conditioning, leather seats, an extra cup holder, and the ability to pick up and move multiple crates at once. + +Again considering the example above, the crates begin in the same configuration: + + [D] +[N] [C] +[Z] [M] [P] + 1 2 3 +Moving a single crate from stack 2 to stack 1 behaves the same as before: + +[D] +[N] [C] +[Z] [M] [P] + 1 2 3 +However, the action of moving three crates from stack 1 to stack 3 means that those three moved crates stay in the same order, resulting in this new configuration: + + [D] + [N] + [C] [Z] + [M] [P] + 1 2 3 +Next, as both crates are moved from stack 2 to stack 1, they retain their order as well: + + [D] + [N] +[C] [Z] +[M] [P] + 1 2 3 +Finally, a single crate is still moved from stack 1 to stack 2, but now it's crate C that gets moved: + + [D] + [N] + [Z] +[M] [C] [P] + 1 2 3 +In this example, the CrateMover 9001 has put the crates in a totally different order: MCD. + +Before the rearrangement process finishes, update your simulation so that the Elves know where they should stand to be ready to unload the final supplies. After the rearrangement procedure completes, what crate ends up on top of each stack? + +Your puzzle answer was BRZGFVBTJ. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day06/day06.test/UnitTestProblem.cs b/day06/day06.test/UnitTestProblem.cs new file mode 100644 index 0000000..6869248 --- /dev/null +++ b/day06/day06.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day06.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("7,5,6,10,11"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("19,23,23,29,26"); + } +} \ No newline at end of file diff --git a/day06/day06.test/Usings.cs b/day06/day06.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day06/day06.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day06/day06.test/day06.test.csproj b/day06/day06.test/day06.test.csproj new file mode 100644 index 0000000..0077f16 --- /dev/null +++ b/day06/day06.test/day06.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day06/day06.test/testdata.txt b/day06/day06.test/testdata.txt new file mode 100644 index 0000000..698fdf2 --- /dev/null +++ b/day06/day06.test/testdata.txt @@ -0,0 +1,5 @@ +mjqjpqmgbljsphdztnvjfqwrcgsmlb +bvwbjplbgvbhsrlpgdmjqwftvncz +nppdvjthqldpwncqszvftbrmjlhg +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg +zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw \ No newline at end of file diff --git a/day06/day06/Problem.cs b/day06/day06/Problem.cs new file mode 100644 index 0000000..c92ed9e --- /dev/null +++ b/day06/day06/Problem.cs @@ -0,0 +1,62 @@ +namespace day06; +using System.Text.RegularExpressions; + +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var space = 4; + List lstIdx = new List(); + foreach (var line in lines) + { + var idx = 0; + for (int i = 0; i < line.Length - space; i++) + { + var current = line.Substring(i, space); + //System.Console.WriteLine(current); + if (current.ToArray().Distinct().Count() == space) + { + idx = i + 4; + break; + } + } + lstIdx.Add(idx); + // System.Console.WriteLine($"for space {space} idx is {idx}"); + //1361 + } + + Result1 = string.Join(',', lstIdx); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var space = 14; + List lstIdx = new List(); + foreach (var line in lines) + { + var idx = 0; + for (int i = 0; i < line.Length - space; i++) + { + var current = line.Substring(i, space); + //System.Console.WriteLine(current); + if (current.ToArray().Distinct().Count() == space) + { + idx = i + space; + break; + } + } + lstIdx.Add(idx); + // System.Console.WriteLine($"for space {space} idx is {idx}"); + //3263 + } + + Result2 = string.Join(',', lstIdx); + } +} \ No newline at end of file diff --git a/day06/day06/Program.cs b/day06/day06/Program.cs new file mode 100644 index 0000000..2913fa4 --- /dev/null +++ b/day06/day06/Program.cs @@ -0,0 +1,16 @@ +namespace day06; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day06/day06/day06.csproj b/day06/day06/day06.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day06/day06/day06.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day06/day06/input.txt b/day06/day06/input.txt new file mode 100644 index 0000000..47146af --- /dev/null +++ b/day06/day06/input.txt @@ -0,0 +1 @@ +rhghwwsmsgmgsmmmlzljllrddvsvhvhhnvvrcccwhhvgghchwhvwvcvrrrgtgrgdggfdgffshsllvvslsppglgvgwgswwcbcwbwrrbjbwjjtgjjdzdfdhfddrmmhqhpqhhqghhzssqzqccbwwffzvzffvtftddrbrtrrcjrrmmbmrrrlrppplmplmppfzpfpvpqvpqqdndpndnmnwmwjmwmwbbrhhmzmffwfqwfqwffppvfpvffnwwwwcbwbhbccvmmplmplmmlmplpprbpbllmhlhzhffngfnntrrsrprrvlllvjvmjvvppsrrfnrfnrfrfwrffrsfrflfltfllpfprrthhhnhqnnfwwcttvzzddqsddwpddnrnttvjttjjdjvdjvjnvnrvvchhschhlffjggtqgqnnvrnrsnrsnsvspsnncppvwvvtmmcqmcmscmsmwmvmpvvlqqmbqqlwwtgtztgttpjjbfjjzhzthhzssffwqqdmdcdlclrclrccbmmqjqmqcmmnnsvnntpphhdpdhhtbtdtffhzfhhpwhppwbppfspphdhggzqgzzffdsdfsszcscpscsqcssffhjhnhhlqqdbqqdmdsmddrfddndldgglvglvlggqlggjngjnnbffthhjbjpjnjmnmgmqqbjqjzjqzzzjffwttcnnzffmllcncmnnthnncttpgpnnjdjfftmmvqmqsqggfrfjjqbjbvvshvhphfhhljlfjjvcclzclctcmmfwfvwfvwwjvwvjjplpbpqqdvqqbhbdbnnsndssgffgsglssmfmjjfrjfrfttljldjdffjjdnjjlbbnrntrtfrttmhhndnsdsffgqqrpplvvfwvfvsfszzfzhfzzlttlctllrzrggvwvhhgnnlmnlmlpppdldqqdpdlplrpppjspspzzhphccgjjpmmwvwbwssnpssrzrwrhhmzhmhsmhmttrqrvqvcclggptpjpzpccltctppflfjffrtrjrhjhffhjfjbfjfqfqzffdtthwwjwzjzggsgzgqqjdqjddvgvsvnnqwqgwgtttfvfrfwrfwfwmwmqwmmmbzmzvzfvfrfvvgvtvptpbpwbwrbwrwffzzfgzfgfcfzcffjdjjvrvnnfmmtztffsggjcjzcjcssscnscnssmmwgwbbljlnjndnrrqwqjjjbnnmbmcmbcmbbvvmtvmmfcmcjcdcnnzfzfzqfzfvvmbvmmndnbnsnnlddqvvsnngvnnrttfbtbqqnwqqzfzfzccfmmgrrsbbhvvgjjhfhssjmmsjjzzbqblqlfqllwhlwwvvstvtfvttnncjjzcjcjrrsvrssmfsfczbrzrvscvmcmrjpzwhcqfrrzbljnmqlzbzqtmhrshlrjjpvhnsvtlhqggqwppsjpszmqwfqmlwbqzwcrggrvfbvztnflwvbrqcrqbcllswvsvhwjzpldgphwptfdnlgdlnbttjfzrdcfvpdhlssfsljvdjmwddbnrpqnnqlfdfdspbnjwqjwrgtnrftsqcfjpmqwgwhttggjwzvgbwlhmtmmjlwhssrgshzpbcnstzlqdshdhjfgqlsmqqhpwbscsjhfbhprvhmftqngjgdbcvfldqgqsjqjfdmcvsflwzflsjfssnjpbwffnsfcnrdsphbjpgghmcthgnzmpgppqjdvbztvhnwqzndntcpjdtwwhvsmgdcthpssszrqcbntgsznpghmbqddpqscntjprlwzhbzhjtwzbwwcldwdgsttzmtnstjnngzrgvhncdbgqnllfzbthldztsdwsngjzprbvrnbzrsghlgssbqfnbvhnhzwmmmtncvsdngdtwcbjlnnzbnlrnmrvnvsjnvzdqnggmsvljlvjznwdszcmblhrsjvczpnlhsmqjsmwhbjbplbtqsgqjdllhncwdgbvzwnmqvndcbfhnvtjnzmvjhwzvdldhgfwbqqzcnbflfnwntlhmqgdhmrgwqcpmsvfbmwhbtsbdlhcnbcbswvdfffgjvddrbpzpcwsrsjnfvmzhlvbdnwttnqrmzbnnntbfvptrlhjhwjcsbnhvtwtwzvgfnzjplthqjbsjjwzdtqqvblnbvgcmvrmnvmwfrhcqgvrcjlfzdlpbfvncbtfgvnsflbjzqqhczcmtbwqmrppmptfgzvfbmcslwlfrfpvvnvvnwfvvmmdzmmtjsgqdfhngtphtlfjqrtljgnthgnbbqfrnpfmpwhpzdvzmtswwdvcnpsdcqwjdwlvbsbmlwdsjbcbgcrfljshlvpngfmsrzlfhtfqgwbcctnzzhnqhdmqzdwthftwtmpbcmqvdcdtgvltbzmszzwwmhzlfvbdqnhjqgdmstsnhftcwzvvbmnhwvgqzscwcdjbdgfmvpjdzctwqwltbwjlgcblnnhpnmggbmvqpqtgqjzspgqzvcvsdbvjgjfzdzhfpbzjqljjcgldzgnlmtjcmfgdbqgglvjqrppwmhccvqzvsrjjvfhjprwdsqsnszfprznljtcsrtqhcrpljfrccflmbpvqtzgmzhjrlbnrmmsmmjbtzwpglqgdvvvjvnfzmplsmvlvcnjshvjwntclwgpznnzwhjssgdcjbzrmsgnfgcgphrhfvrfhzwdcvsplhbmqwhpmjvqlmschznbqblvhtqfgtdggmncndhhplnzjphccjmlmtdqnmnlnpnfqdstljqnsqbrjrtspvrwvdmwzlgdmsfvctzgtmgqhqqrzpbgplzcfdqnzhsqrbcvhsccshnnpvvrpvqzqsgzgmpzfvvrrcvhdtntnsqnjrbzlbzmpgwdqzbhtlrrhbwdqjlsfgdhmvgmgbqhwvljmmqfllqvvrznrlftgzjdcgtstjffqmgvffpvtctzpdqjfnmlcdzscntctmqhrtmhrlhbjzttrcvcnlhsrvtpbmdchhntnnpnzlvqqnsrjcmblcvphqgwshnjmplgvnbsmmdzgqcpqztjhhgjvtlbpdpdwlwmmfrdgcvzfbgvbgpbjnwsssvhszwplcgvpgjwdrwngbcdjwvlsfhqlrqzgrzpfgjstqfdbrpqdvrlgdwqcsrgvhctznjjlzsmzctsqtfnhhlpjgnltssglmlwshfbrgmjqbvsmqwvszdfsvhmtrfjgwjctpsmgzzjbpwsztnnvzrhwvvmhdpgdmwzsjprhlgzcdvhznlfgjqvcwqrplcfvzmthsdsnrtfvnlrmvwplmbdvdggmlvpgdgzhvzmvzwmptzsnfrcrjspccmqjpjmhjqgrjbdcdjbzjmphmcdvjqtmdshhjrqgjgsnpzfbfgpjpczwzvmclgzgztlvzmdbwgncnndjwhhhjnhtjdmcnrmnqbmjdrdcmtvcsmftqcfhsvhsfjmtzjpnwffggpfqlqmzlbhnnhbtgzfgnjvdzmvthqjrhzbwvhcjzcsmsvsctrqbltpcrpjjnsbjdbfjqfcbpcgcwtqsflmlwprjcwlmcjjgsfdpwcqvhjpsgvdgsfnscnbzsrmrbbvdrlltzplbvgqsdnplcvbhddbtmwnfmvqhqdlrtrmrmzmhlccgwgmbdppjqdjtwmvdzfsbsggrfstjwjpjnljffwffmqncfnthnhglwvsgvzmgbzhtdfpfmdwmcldthvsnqnptpmhqctblgfsszhcfbvcrggjdhthqvvvlldshvqwmvdtfslrhzvgdfwztrczdjgcfcgtmwnphqthlgpfnrqwcgpzwnlgdvsnvzftlnlfflfsmjzhrhqjctsbvtccwbfsdrnbhszzjhqndvwcsmffnstnfdfwpbgfztjmjngdczzlgpscjtshpmmmzlnqndsttbdgfjqcvbqlphwhlhgcvjbhjmtrfzlgpwdnvzrllndbhvhlngvhlszzdcrdgvrmjwcvhhtbhnjmdzgctqnpdlrnqjzbchjtcsggsczlgmvtqvzmsqvtrhtvdmzlcdddfnbvbsnrzvgzfqjtbhjqhdznrhbfbqwtnwvrfqsznbqfzfzfgmhvjjsgbbdbdtzswwlnfrq \ No newline at end of file diff --git a/day06/problem.md b/day06/problem.md new file mode 100644 index 0000000..5528a63 --- /dev/null +++ b/day06/problem.md @@ -0,0 +1,55 @@ +--- Day 6: Tuning Trouble --- +The preparations are finally complete; you and the Elves leave camp on foot and begin to make your way toward the star fruit grove. + +As you move through the dense undergrowth, one of the Elves gives you a handheld device. He says that it has many fancy features, but the most important one to set up right now is the communication system. + +However, because he's heard you have significant experience dealing with signal-based systems, he convinced the other Elves that it would be okay to give you their one malfunctioning device - surely you'll have no problem fixing it. + +As if inspired by comedic timing, the device emits a few colorful sparks. + +To be able to communicate with the Elves, the device needs to lock on to their signal. The signal is a series of seemingly-random characters that the device receives one at a time. + +To fix the communication system, you need to add a subroutine to the device that detects a start-of-packet marker in the datastream. In the protocol being used by the Elves, the start of a packet is indicated by a sequence of four characters that are all different. + +The device will send your subroutine a datastream buffer (your puzzle input); your subroutine needs to identify the first position where the four most recently received characters were all different. Specifically, it needs to report the number of characters from the beginning of the buffer to the end of the first such four-character marker. + +For example, suppose you receive the following datastream buffer: + +mjqjpqmgbljsphdztnvjfqwrcgsmlb +After the first three characters (mjq) have been received, there haven't been enough characters received yet to find the marker. The first time a marker could occur is after the fourth character is received, making the most recent four characters mjqj. Because j is repeated, this isn't a marker. + +The first time a marker appears is after the seventh character arrives. Once it does, the last four characters received are jpqm, which are all different. In this case, your subroutine should report the value 7, because the first start-of-packet marker is complete after 7 characters have been processed. + +Here are a few more examples: + +bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 5 +nppdvjthqldpwncqszvftbrmjlhg: first marker after character 6 +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 10 +zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 11 +How many characters need to be processed before the first start-of-packet marker is detected? + +Your puzzle answer was 1361. + +--- Part Two --- +Your device's communication system is correctly detecting packets, but still isn't working. It looks like it also needs to look for messages. + +A start-of-message marker is just like a start-of-packet marker, except it consists of 14 distinct characters rather than 4. + +Here are the first positions of start-of-message markers for all of the above examples: + +mjqjpqmgbljsphdztnvjfqwrcgsmlb: first marker after character 19 +bvwbjplbgvbhsrlpgdmjqwftvncz: first marker after character 23 +nppdvjthqldpwncqszvftbrmjlhg: first marker after character 23 +nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg: first marker after character 29 +zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw: first marker after character 26 +How many characters need to be processed before the first start-of-message marker is detected? + +Your puzzle answer was 3263. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day07/day07.test/UnitTestProblem.cs b/day07/day07.test/UnitTestProblem.cs new file mode 100644 index 0000000..45e05ae --- /dev/null +++ b/day07/day07.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day07.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("95437"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("24933642"); + } +} \ No newline at end of file diff --git a/day07/day07.test/Usings.cs b/day07/day07.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day07/day07.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day07/day07.test/day07.test.csproj b/day07/day07.test/day07.test.csproj new file mode 100644 index 0000000..7c3634c --- /dev/null +++ b/day07/day07.test/day07.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day07/day07.test/testdata.txt b/day07/day07.test/testdata.txt new file mode 100644 index 0000000..bcbb513 --- /dev/null +++ b/day07/day07.test/testdata.txt @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k \ No newline at end of file diff --git a/day07/day07/GameExtensions.cs b/day07/day07/GameExtensions.cs new file mode 100644 index 0000000..02d7602 --- /dev/null +++ b/day07/day07/GameExtensions.cs @@ -0,0 +1,50 @@ +namespace day07; + +public static class GameExtensions +{ + public static bool IsCommand(this string line, out string cmd) + { + cmd = ""; + if (line.StartsWith("$")) + { + cmd = line.Substring(1).Trim(); + } + return line.StartsWith("$"); + } + public static bool IsCommand(this string line) + { + return line.StartsWith("$"); + } + public static bool IsCdRoot(this string cmd) + { + var cmdparts = cmd.Split(" "); + return cmdparts[0] == "cd" && + cmdparts[1] == "/"; + } + + public static bool IsCdIn(this string cmd, out string folder) + { + var cmdparts = cmd.Split(" "); + folder = cmdparts[0] == "cd" ? cmdparts[1] : ""; + return cmdparts[0] == "cd" && + cmdparts[1] != "/" && + cmdparts[1] != ".."; + } + + public static bool IsCdOut(this string cmd) + { + var cmdparts = cmd.Split(" "); + return cmdparts[0] == "cd" && + cmdparts[1] == ".."; + } + + public static bool IsLs(this string cmd, int i, ref string[] lines, out List lsResult) + { + lsResult = new List(); + while (++i < lines.Length && !lines[i].IsCommand()) + { + lsResult.Add(lines[i]); + } + return cmd == "ls"; + } +} diff --git a/day07/day07/Node.cs b/day07/day07/Node.cs new file mode 100644 index 0000000..7812565 --- /dev/null +++ b/day07/day07/Node.cs @@ -0,0 +1,44 @@ +namespace day07; + +public class Node +{ + private long size = 0; + + public long Size + { + get { return size; } + set + { + if (this.Parent != null) + this.Parent.Size -= size; + size = value; + if (this.Parent != null) + this.Parent.Size += size; + } + } + public Node Parent { get; set; } + public List Childs { get; private set; } = new(); + public NodeType NodeType { get; set; } + public string Name { get; set; } + + public override string ToString() + { + return $"{Enum.GetName(NodeType)} - {FullPath} - {Size}"; + } + + public string FullPath + { + get + { + if (Parent == null) + { + return "/"; + } + else + { + return $"{Parent.FullPath}{Name}/"; + } + } + } + +} diff --git a/day07/day07/NodeType.cs b/day07/day07/NodeType.cs new file mode 100644 index 0000000..48ab8c6 --- /dev/null +++ b/day07/day07/NodeType.cs @@ -0,0 +1,7 @@ +namespace day07; + +public enum NodeType +{ + Directory, + File +} \ No newline at end of file diff --git a/day07/day07/Problem.cs b/day07/day07/Problem.cs new file mode 100644 index 0000000..17724cd --- /dev/null +++ b/day07/day07/Problem.cs @@ -0,0 +1,112 @@ +namespace day07; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + private List allFolders = new List(); + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var currentPath = ""; + + Node root = null; + Node currentNode = null; + + + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i]; + string cmd; + List lsResult; + if (line.IsCommand(out cmd)) + { + string folderIn = ""; + if (cmd.IsCdRoot()) + { + currentPath = "/"; + if (root == null) + { + root = new Node() + { + Name = "/", + NodeType = NodeType.Directory + }; + } + currentNode = root; + if (!allFolders.Contains(root)) + { + allFolders.Add(root); + } + } + else if (cmd.IsCdIn(out folderIn)) + { + currentNode = currentNode.Childs.Find(x => x.Name == folderIn); + } + else if (cmd.IsCdOut()) + { + currentNode = currentNode.Parent; + } + else if (cmd.IsLs(i, ref lines, out lsResult)) + { + i += lsResult.Count; + foreach (var result in lsResult) + { + var entryParts = result.Split(" "); + var nodeEntry = new Node + { + NodeType = entryParts[0] == "dir" ? NodeType.Directory : NodeType.File, + Name = entryParts[1], + Parent = currentNode + }; + currentNode.Childs.Add(nodeEntry); + nodeEntry.Size = entryParts[0] != "dir" ? long.Parse(entryParts[0]) : 0; + // + if (nodeEntry.NodeType == NodeType.Directory) + { + if (!allFolders.Contains(nodeEntry)) + { + allFolders.Add(nodeEntry); + } + } + } + i--; + } + } + } + + // + var sum1 = allFolders.Where(x => (x.Size <= 100000)) + .Sum(x => x.Size); + // System.Console.WriteLine(sum1); + //95437 + //1206825 + + Result1 = sum1.ToString(); + } + + public void ResolvePart2(string arg) + { + ResolvePart1(arg); + + var theroot = allFolders.Find(x => x.Parent == null); + var diskSize = 70000000; + var neededSpace = 30000000; + var currentSpace = diskSize - theroot.Size; + // System.Console.WriteLine(currentSpace); + var extraNeededSpace = neededSpace - currentSpace; + // System.Console.WriteLine(extraNeededSpace); + var pickedDirectoryForDelete = allFolders + .Where(x => x.Size >= extraNeededSpace) + .OrderBy(x => x.Size) + .First(); + // System.Console.WriteLine(pickedDirectoryForDelete); + //24933642 + //9608311 + + + Result2 = pickedDirectoryForDelete.Size.ToString(); + } +} diff --git a/day07/day07/Program.cs b/day07/day07/Program.cs new file mode 100644 index 0000000..15e93c1 --- /dev/null +++ b/day07/day07/Program.cs @@ -0,0 +1,16 @@ +namespace day07; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day07/day07/day07.csproj b/day07/day07/day07.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day07/day07/day07.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day07/day07/input.txt b/day07/day07/input.txt new file mode 100644 index 0000000..2ba6559 --- /dev/null +++ b/day07/day07/input.txt @@ -0,0 +1,1017 @@ +$ cd / +$ ls +dir bntdgzs +179593 cjw.jgc +110209 grbwdwsm.znn +dir hsswswtq +dir jdfwmhg +dir jlcbpsr +70323 qdtbvqjj +48606 qdtbvqjj.zdg +dir tvcr +dir vhjbjr +dir vvsg +270523 wpsjfqtn.ljt +$ cd bntdgzs +$ ls +297955 gcwcp +$ cd .. +$ cd hsswswtq +$ ls +dir bsjbvff +dir dpgvp +267138 grbwdwsm.znn +dir hldgfpvh +dir jdfwmhg +dir jtgdv +93274 ptsd.nzh +268335 qdtbvqjj.dlh +185530 qdtbvqjj.jrw +dir vcbqdj +dir wtrsg +$ cd bsjbvff +$ ls +dir dmnt +148799 grbwdwsm.znn +324931 hzmqrfc.lsd +211089 qdtbvqjj +$ cd dmnt +$ ls +221038 zht +$ cd .. +$ cd .. +$ cd dpgvp +$ ls +dir fzttpjtd +dir jdrbwrc +dir rwz +dir tssm +$ cd fzttpjtd +$ ls +149872 jdfwmhg +$ cd .. +$ cd jdrbwrc +$ ls +149973 hpgg.srm +dir ptsd +$ cd ptsd +$ ls +2594 twzf.pqq +$ cd .. +$ cd .. +$ cd rwz +$ ls +dir jdfwmhg +302808 zzlh +$ cd jdfwmhg +$ ls +229683 cdcrgcmh +218733 nhzt +$ cd .. +$ cd .. +$ cd tssm +$ ls +dir ptsd +37272 qfnnrqsh.qvg +215066 wnvjc.jqf +$ cd ptsd +$ ls +24102 bwtbht.dwq +224035 qdtbvqjj.dmp +$ cd .. +$ cd .. +$ cd .. +$ cd hldgfpvh +$ ls +316712 grbwdwsm.znn +328950 tqvgqjrr +$ cd .. +$ cd jdfwmhg +$ ls +130652 gcwcp +dir jdfwmhg +215427 lfw.zml +dir qdtbvqjj +4181 rgsvgssj.qsr +$ cd jdfwmhg +$ ls +dir bvm +dir hsswswtq +122279 qznt.jhl +dir sjw +dir zpfdtl +$ cd bvm +$ ls +22841 fbcgh.mrp +dir hsswswtq +dir hstg +41317 ndrt +dir nvmvghb +239316 ptsd +dir qtwvdtsp +98555 vzh +$ cd hsswswtq +$ ls +dir ddcjvjgf +127104 plwvb.pbj +dir ptsd +dir qhp +dir rjtrhgwh +$ cd ddcjvjgf +$ ls +135870 bwtbht.dwq +81968 gcwcp +182253 mrbh.wmc +275931 nsrqrts +322128 pfpcp +$ cd .. +$ cd ptsd +$ ls +214981 jsrlsc +dir wpbdrcw +$ cd wpbdrcw +$ ls +197849 mljfb.ggb +173586 ptsd +$ cd .. +$ cd .. +$ cd qhp +$ ls +293198 bnrgl +$ cd .. +$ cd rjtrhgwh +$ ls +224393 clrp.nst +$ cd .. +$ cd .. +$ cd hstg +$ ls +51671 gdsfpc +209216 hsswswtq +97203 jlnr +dir thdhg +57399 tssm +$ cd thdhg +$ ls +201896 jjp.wvw +$ cd .. +$ cd .. +$ cd nvmvghb +$ ls +210047 gfcrzgj +dir rqjbplv +dir rvwd +292931 sgwvcqfr.bpq +dir vtjd +$ cd rqjbplv +$ ls +105204 gcwcp +$ cd .. +$ cd rvwd +$ ls +66170 jdfwmhg +$ cd .. +$ cd vtjd +$ ls +dir ptsd +$ cd ptsd +$ ls +300524 bwtbht.dwq +$ cd .. +$ cd .. +$ cd .. +$ cd qtwvdtsp +$ ls +289574 wctgtq +$ cd .. +$ cd .. +$ cd hsswswtq +$ ls +24935 gcwcp +dir jzpbdcmc +26834 mljfb.ggb +182501 phnmlsjp.pjc +dir pttnl +dir qdtbvqjj +dir vst +$ cd jzpbdcmc +$ ls +297521 grbwdwsm.znn +dir qwc +dir zzswd +$ cd qwc +$ ls +81143 hsswswtq.rjw +54843 mjvvfsz.rgz +273051 pfwgtmtt.ccs +$ cd .. +$ cd zzswd +$ ls +216062 vlbwz.zmh +$ cd .. +$ cd .. +$ cd pttnl +$ ls +257733 mljfb.ggb +250887 pfwgtmtt.ccs +$ cd .. +$ cd qdtbvqjj +$ ls +34667 gcwcp +$ cd .. +$ cd vst +$ ls +70250 pfwgtmtt.ccs +dir zpcqhml +$ cd zpcqhml +$ ls +219936 jdfwmhg.zbm +$ cd .. +$ cd .. +$ cd .. +$ cd sjw +$ ls +152311 nqjtvzff +157117 pfwgtmtt.ccs +118226 ptsd.vsm +$ cd .. +$ cd zpfdtl +$ ls +189042 gcwcp +$ cd .. +$ cd .. +$ cd qdtbvqjj +$ ls +dir ftz +dir hvlffb +dir lzbb +53335 ptsd +dir qdtbvqjj +$ cd ftz +$ ls +dir fft +256058 gcwcp +497 hsswswtq.vqs +103941 hvtcz.fsg +171587 ljlnz.ffg +115101 mljfb.ggb +dir qdtbvqjj +$ cd fft +$ ls +58845 bwtbht.dwq +136040 gcwcp +256973 mljfb.ggb +$ cd .. +$ cd qdtbvqjj +$ ls +dir fgqhdh +304573 ntm.wmc +$ cd fgqhdh +$ ls +317143 gcwcp +26010 lsfpfdqz +$ cd .. +$ cd .. +$ cd .. +$ cd hvlffb +$ ls +6682 vjt.mcf +$ cd .. +$ cd lzbb +$ ls +dir bbvml +324162 bwtbht.dwq +dir fjs +dir pffntc +dir pnltt +dir ptsd +$ cd bbvml +$ ls +dir qdtbvqjj +dir qssdcrp +dir tssm +$ cd qdtbvqjj +$ ls +246275 qdtbvqjj.cgn +$ cd .. +$ cd qssdcrp +$ ls +274399 hsswswtq +$ cd .. +$ cd tssm +$ ls +dir ssqc +$ cd ssqc +$ ls +178904 njrssmlm.gcm +$ cd .. +$ cd .. +$ cd .. +$ cd fjs +$ ls +dir dmvnp +121967 fqlzlvwt +204348 grbwdwsm.znn +102733 jdfwmhg.qsl +240279 ptsd.jwm +228793 ptsd.nsh +dir ssm +$ cd dmvnp +$ ls +dir psj +dir zjw +$ cd psj +$ ls +170665 gcwcp +56058 lsfzc.dcp +40658 tfsllqqw.fgv +$ cd .. +$ cd zjw +$ ls +79989 fggsl.dmz +$ cd .. +$ cd .. +$ cd ssm +$ ls +106263 bwtbht.dwq +106259 jdfwmhg.qtb +6246 rwbnr.tqv +$ cd .. +$ cd .. +$ cd pffntc +$ ls +111475 qbmrdms.ldm +$ cd .. +$ cd pnltt +$ ls +dir nptfhlf +dir zngmf +$ cd nptfhlf +$ ls +223065 qrb.drh +205674 rdgfz +$ cd .. +$ cd zngmf +$ ls +61655 bwtbht.dwq +$ cd .. +$ cd .. +$ cd ptsd +$ ls +dir hrvrt +dir thwtl +$ cd hrvrt +$ ls +152296 pfwgtmtt.ccs +$ cd .. +$ cd thwtl +$ ls +156783 pfwgtmtt.ccs +323304 sltc +$ cd .. +$ cd .. +$ cd .. +$ cd qdtbvqjj +$ ls +320175 pfwgtmtt.ccs +$ cd .. +$ cd .. +$ cd .. +$ cd jtgdv +$ ls +81164 ptsd.tpj +$ cd .. +$ cd vcbqdj +$ ls +dir crng +330203 gvlrg +152022 qdtbvqjj.slq +294095 rthwj.zrf +dir vjsbf +$ cd crng +$ ls +dir gznrh +$ cd gznrh +$ ls +259458 ptsd +$ cd .. +$ cd .. +$ cd vjsbf +$ ls +47331 hlld.fzf +147103 jdfwmhg +$ cd .. +$ cd .. +$ cd wtrsg +$ ls +144344 dtcc +$ cd .. +$ cd .. +$ cd jdfwmhg +$ ls +323973 qdtbvqjj +$ cd .. +$ cd jlcbpsr +$ ls +dir htrdwm +dir jdfwmhg +dir pwmvbhsl +dir vwfdfmcp +$ cd htrdwm +$ ls +dir btn +105731 dlncqrbm.dgl +158267 gqqghldt +242513 hsswswtq.drj +dir jdfwmhg +212816 swsgtv.wbb +228996 tgll.rcs +$ cd btn +$ ls +50419 pfwgtmtt.ccs +$ cd .. +$ cd jdfwmhg +$ ls +dir bwc +$ cd bwc +$ ls +184634 cfwg +$ cd .. +$ cd .. +$ cd .. +$ cd jdfwmhg +$ ls +319749 hsswswtq +dir jdfwmhg +271619 jdfwmhg.znz +dir jhmmt +181217 mljfb.ggb +11297 rcpl.tgf +83423 zwscbcvm.ths +$ cd jdfwmhg +$ ls +267171 cts.hlf +$ cd .. +$ cd jhmmt +$ ls +84473 jdfwmhg +$ cd .. +$ cd .. +$ cd pwmvbhsl +$ ls +dir jsg +171725 mljfb.ggb +152612 qjr +dir vfsqw +$ cd jsg +$ ls +176951 jdfwmhg.fhn +284927 ljvvtw.wcq +153109 vnvtt +$ cd .. +$ cd vfsqw +$ ls +104559 htsrns.gws +$ cd .. +$ cd .. +$ cd vwfdfmcp +$ ls +291404 csmvbjlt.tdf +$ cd .. +$ cd .. +$ cd tvcr +$ ls +dir djtwv +dir hsswswtq +272845 mdds +dir ndshbjzn +65929 scpltww.twm +dir tssm +30516 zdpscm +dir zqdrdzv +$ cd djtwv +$ ls +271696 cwjj.hjp +$ cd .. +$ cd hsswswtq +$ ls +dir djngm +dir hcz +dir ptsd +$ cd djngm +$ ls +317775 ltwjzpjb.rcj +37776 qdtbvqjj.lzf +$ cd .. +$ cd hcz +$ ls +217741 pgdmr +128868 qdtbvqjj +306138 zbmrplsn +$ cd .. +$ cd ptsd +$ ls +304048 ftm +120236 mdcwvvng +$ cd .. +$ cd .. +$ cd ndshbjzn +$ ls +206408 pfwgtmtt.ccs +$ cd .. +$ cd tssm +$ ls +dir mlcnsf +dir nbgjm +204079 pdljvb +185465 rqgdmbjf.rhr +dir sfnlb +$ cd mlcnsf +$ ls +249868 fqrncwd +29146 zdz.jth +$ cd .. +$ cd nbgjm +$ ls +113314 mljfb.ggb +$ cd .. +$ cd sfnlb +$ ls +234917 tjp +$ cd .. +$ cd .. +$ cd zqdrdzv +$ ls +40790 vtdnhzm +$ cd .. +$ cd .. +$ cd vhjbjr +$ ls +dir glv +dir mvns +dir qbrnh +$ cd glv +$ ls +288849 bgvqll.sfj +259105 jdfwmhg +dir qcjlshcv +$ cd qcjlshcv +$ ls +dir nwqqjcmh +$ cd nwqqjcmh +$ ls +137244 grbwdwsm.znn +312904 mzh +dir qdtbvqjj +$ cd qdtbvqjj +$ ls +dir nlqbq +$ cd nlqbq +$ ls +307636 ptsd.vtr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd mvns +$ ls +dir gzqlmrdh +dir qjhtlh +dir tssm +dir vthg +$ cd gzqlmrdh +$ ls +274950 mlzdqwm +$ cd .. +$ cd qjhtlh +$ ls +157835 ptsd.lqm +300380 wst.trp +$ cd .. +$ cd tssm +$ ls +15772 gcwcp +$ cd .. +$ cd vthg +$ ls +dir gdndtlnc +$ cd gdndtlnc +$ ls +3175 hsswswtq.bds +320462 mljfb.ggb +305508 mzvtzvqc +dir qdtbvqjj +154575 tssm.vgb +$ cd qdtbvqjj +$ ls +236889 drnnvh +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd qbrnh +$ ls +dir hsswswtq +4623 hsswswtq.rnf +266326 jrmq.ztg +295980 tssm.vzb +dir wnbfzd +dir zjzhncs +dir zttlggt +$ cd hsswswtq +$ ls +48277 gsqjdbhv +$ cd .. +$ cd wnbfzd +$ ls +97133 mljfb.ggb +$ cd .. +$ cd zjzhncs +$ ls +298303 gcwcp +dir ggr +113206 grbwdwsm.znn +$ cd ggr +$ ls +244876 ptsd.zvb +$ cd .. +$ cd .. +$ cd zttlggt +$ ls +dir hdbwrcm +dir mbvpd +dir mtd +dir ptsd +dir tcwqp +$ cd hdbwrcm +$ ls +267323 bwtbht.dwq +$ cd .. +$ cd mbvpd +$ ls +84087 frf.smv +$ cd .. +$ cd mtd +$ ls +158543 mljfb.ggb +$ cd .. +$ cd ptsd +$ ls +112797 vtschwnb.fnp +$ cd .. +$ cd tcwqp +$ ls +90637 lbsqcj.sfn +179097 tssm.dbl +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd vvsg +$ ls +168715 bwtbht.dwq +dir bwv +dir hsswswtq +dir lqmnjrlb +dir mmrfrj +175244 vct.tsc +dir zwvlhs +$ cd bwv +$ ls +201509 gcwcp +62815 grbwdwsm.znn +dir gwdh +dir mfdvcn +166355 pfwgtmtt.ccs +dir ptsd +169681 qdtbvqjj.fgh +250573 wvndzgv +$ cd gwdh +$ ls +306377 sphrj.pjh +$ cd .. +$ cd mfdvcn +$ ls +27796 bvclvtrm.jlf +65045 cghr.vzg +dir hsswswtq +197145 jdqztgh.pvd +$ cd hsswswtq +$ ls +298155 bwtbht.dwq +$ cd .. +$ cd .. +$ cd ptsd +$ ls +27501 grbwdwsm.znn +231999 jdnsv +113528 rmfmb.zzw +dir tssm +dir vgjfsh +$ cd tssm +$ ls +dir dndv +226375 grbwdwsm.znn +$ cd dndv +$ ls +152739 sdjrzcv.tvs +$ cd .. +$ cd .. +$ cd vgjfsh +$ ls +211409 swtbttb.vrp +170879 vvfnf.hrp +$ cd .. +$ cd .. +$ cd .. +$ cd hsswswtq +$ ls +dir qdtbvqjj +dir tssm +86418 vhsgq +$ cd qdtbvqjj +$ ls +118588 bwtbht.dwq +$ cd .. +$ cd tssm +$ ls +113460 gml.wdg +$ cd .. +$ cd .. +$ cd lqmnjrlb +$ ls +dir tssm +$ cd tssm +$ ls +dir jdfwmhg +$ cd jdfwmhg +$ ls +64663 nswd.rwc +$ cd .. +$ cd .. +$ cd .. +$ cd mmrfrj +$ ls +319070 gltlwnlt.jzw +232039 hspr +104688 hsswswtq.jsr +dir jdfwmhg +88712 jdfwmhg.zcw +dir pfr +dir prnnpwcd +45488 qdtbvqjj +dir tssm +dir wcmwrtjn +$ cd jdfwmhg +$ ls +140910 bjjhtzct.stm +$ cd .. +$ cd pfr +$ ls +289538 qdtbvqjj +217502 vvpwf +$ cd .. +$ cd prnnpwcd +$ ls +dir qdtbvqjj +$ cd qdtbvqjj +$ ls +dir pqg +dir tssm +$ cd pqg +$ ls +222392 ptsd.ggr +$ cd .. +$ cd tssm +$ ls +158252 dcnvjj.zfd +10486 jdfwmhg.qmb +4374 qdtbvqjj.vqm +254229 vgqfw +$ cd .. +$ cd .. +$ cd .. +$ cd tssm +$ ls +dir ptsd +$ cd ptsd +$ ls +173766 fvlsgqb +35658 wtc.vvd +$ cd .. +$ cd .. +$ cd wcmwrtjn +$ ls +160089 chfhpc +76202 frgpdnd.ngw +138996 jsfsfpqg.nhf +dir mlm +dir nbdbzsn +dir ptsd +278574 vrnb +$ cd mlm +$ ls +dir gqwhhmvd +dir nrzvzgrt +dir nzplht +dir zzp +$ cd gqwhhmvd +$ ls +dir ddmvjpj +dir jdfwmhg +$ cd ddmvjpj +$ ls +273423 jdfwmhg +43605 pfwgtmtt.ccs +$ cd .. +$ cd jdfwmhg +$ ls +239406 qctw.vzb +$ cd .. +$ cd .. +$ cd nrzvzgrt +$ ls +20712 gcwcp +239372 gjgdvbwb.gcz +dir hdzhl +124814 jdfwmhg +dir jfzr +295071 qwjgwqp +221611 shrzpsj.dwh +dir tssm +dir wdlsvzvl +$ cd hdzhl +$ ls +dir gfwbd +184323 hsswswtq.mln +177147 nqgqz.tnf +4680 pfwgtmtt.ccs +$ cd gfwbd +$ ls +254870 cldm.fft +301411 tssm.cvn +$ cd .. +$ cd .. +$ cd jfzr +$ ls +dir dvvflnnw +dir jdfwmhg +216389 lwtwn.ttt +201727 pfwgtmtt.ccs +107829 prphc.ncb +5816 sdvq.jvn +$ cd dvvflnnw +$ ls +24741 brtrbwh.wwd +27700 mljfb.ggb +$ cd .. +$ cd jdfwmhg +$ ls +325218 bwtbht.dwq +63718 mvl.ngz +162645 vtd.vgp +$ cd .. +$ cd .. +$ cd tssm +$ ls +60903 pfwgtmtt.ccs +332768 qdtbvqjj.jwb +$ cd .. +$ cd wdlsvzvl +$ ls +142213 vgvd +$ cd .. +$ cd .. +$ cd nzplht +$ ls +275904 hsswswtq +157369 jdfwmhg +84363 jvcvmbm.fht +dir qbjqgg +$ cd qbjqgg +$ ls +331934 gcwcp +$ cd .. +$ cd .. +$ cd zzp +$ ls +151335 flsd.zmj +dir gwlhqlp +99086 jdfwmhg.hft +$ cd gwlhqlp +$ ls +201894 glcnpqzp.jvc +$ cd .. +$ cd .. +$ cd .. +$ cd nbdbzsn +$ ls +169929 bwtbht.dwq +$ cd .. +$ cd ptsd +$ ls +128999 bwtbht.dwq +dir jtlrn +dir pszlt +dir ptjnh +dir ptsd +2981 qdtbvqjj.qcn +dir rpb +dir tcjgpqj +dir tmddnh +dir tssm +$ cd jtlrn +$ ls +124888 grbwdwsm.znn +30046 jznz.dwf +$ cd .. +$ cd pszlt +$ ls +154368 dbblsg.mzr +$ cd .. +$ cd ptjnh +$ ls +306974 grbwdwsm.znn +82840 ptsd +$ cd .. +$ cd ptsd +$ ls +dir ftjhsb +dir jdfwmhg +304012 lqgtvmrl.qbj +96971 mljfb.ggb +$ cd ftjhsb +$ ls +56965 dhgds +$ cd .. +$ cd jdfwmhg +$ ls +dir lssbmtms +dir vmwshd +$ cd lssbmtms +$ ls +95453 gcwcp +198402 mljfb.ggb +1507 mzlmp +40526 twlqhml +$ cd .. +$ cd vmwshd +$ ls +267087 pfwgtmtt.ccs +$ cd .. +$ cd .. +$ cd .. +$ cd rpb +$ ls +dir lqbchlbp +dir ptsd +$ cd lqbchlbp +$ ls +151429 ptsd.tjz +$ cd .. +$ cd ptsd +$ ls +28900 gcwcp +55920 llt +$ cd .. +$ cd .. +$ cd tcjgpqj +$ ls +dir cvdlcvq +329232 hcmj.nvp +232764 nvtmgc.qgs +108056 ptsd.gcn +39056 qdtbvqjj +91792 tssm.wqz +$ cd cvdlcvq +$ ls +46978 grbwdwsm.znn +17760 qrdbsdpj.dhm +$ cd .. +$ cd .. +$ cd tmddnh +$ ls +238434 gggvq.tfc +$ cd .. +$ cd tssm +$ ls +dir tlllv +$ cd tlllv +$ ls +198184 trmf.qqw +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zwvlhs +$ ls +19923 gcwcp +129179 grbwdwsm.znn +214660 pghcvh +101270 ptsd.gzl +dir srjlz +$ cd srjlz +$ ls +221301 nrcg.pqw \ No newline at end of file diff --git a/day07/problem.md b/day07/problem.md new file mode 100644 index 0000000..00d4cec --- /dev/null +++ b/day07/problem.md @@ -0,0 +1,103 @@ +--- Day 7: No Space Left On Device --- +You can hear birds chirping and raindrops hitting leaves as the expedition proceeds. Occasionally, you can even hear much louder sounds in the distance; how big do the animals get out here, anyway? + +The device the Elves gave you has problems with more than just its communication system. You try to run a system update: + +$ system-update --please --pretty-please-with-sugar-on-top +Error: No space left on device +Perhaps you can delete some files to make space for the update? + +You browse around the filesystem to assess the situation and save the resulting terminal output (your puzzle input). For example: + +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k +The filesystem consists of a tree of files (plain data) and directories (which can contain other directories or files). The outermost directory is called /. You can navigate around the filesystem, moving into or out of directories and listing the contents of the directory you're currently in. + +Within the terminal output, lines that begin with $ are commands you executed, very much like some modern computers: + +cd means change directory. This changes which directory is the current directory, but the specific result depends on the argument: +cd x moves in one level: it looks in the current directory for the directory named x and makes it the current directory. +cd .. moves out one level: it finds the directory that contains the current directory, then makes that directory the current directory. +cd / switches the current directory to the outermost directory, /. +ls means list. It prints out all of the files and directories immediately contained by the current directory: +123 abc means that the current directory contains a file named abc with size 123. +dir xyz means that the current directory contains a directory named xyz. +Given the commands and output in the example above, you can determine that the filesystem looks visually like this: + +- / (dir) + - a (dir) + - e (dir) + - i (file, size=584) + - f (file, size=29116) + - g (file, size=2557) + - h.lst (file, size=62596) + - b.txt (file, size=14848514) + - c.dat (file, size=8504156) + - d (dir) + - j (file, size=4060174) + - d.log (file, size=8033020) + - d.ext (file, size=5626152) + - k (file, size=7214296) +Here, there are four directories: / (the outermost directory), a and d (which are in /), and e (which is in a). These directories also contain files of various sizes. + +Since the disk is full, your first step should probably be to find directories that are good candidates for deletion. To do this, you need to determine the total size of each directory. The total size of a directory is the sum of the sizes of the files it contains, directly or indirectly. (Directories themselves do not count as having any intrinsic size.) + +The total sizes of the directories above can be found as follows: + +The total size of directory e is 584 because it contains a single file i of size 584 and no other directories. +The directory a has total size 94853 because it contains files f (size 29116), g (size 2557), and h.lst (size 62596), plus file i indirectly (a contains e which contains i). +Directory d has total size 24933642. +As the outermost directory, / contains every file. Its total size is 48381165, the sum of the size of every file. +To begin, find all of the directories with a total size of at most 100000, then calculate the sum of their total sizes. In the example above, these directories are a and e; the sum of their total sizes is 95437 (94853 + 584). (As in this example, this process can count files more than once!) + +Find all of the directories with a total size of at most 100000. What is the sum of the total sizes of those directories? + +Your puzzle answer was 1206825. + +--- Part Two --- +Now, you're ready to choose a directory to delete. + +The total disk space available to the filesystem is 70000000. To run the update, you need unused space of at least 30000000. You need to find a directory you can delete that will free up enough space to run the update. + +In the example above, the total size of the outermost directory (and thus the total amount of used space) is 48381165; this means that the size of the unused space must currently be 21618835, which isn't quite the 30000000 required by the update. Therefore, the update still requires a directory with total size of at least 8381165 to be deleted before it can run. + +To achieve this, you have the following options: + +Delete directory e, which would increase unused space by 584. +Delete directory a, which would increase unused space by 94853. +Delete directory d, which would increase unused space by 24933642. +Delete directory /, which would increase unused space by 48381165. +Directories e and a are both too small; deleting them would not free up enough space. However, directories d and / are both big enough! Between these, choose the smallest: d, increasing unused space by 24933642. + +Find the smallest directory that, if deleted, would free up enough space on the filesystem to run the update. What is the total size of that directory? + +Your puzzle answer was 9608311. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day08/day08.test/UnitTestProblem.cs b/day08/day08.test/UnitTestProblem.cs new file mode 100644 index 0000000..ecd8f20 --- /dev/null +++ b/day08/day08.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day08.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("21"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("8"); + } +} \ No newline at end of file diff --git a/day08/day08.test/Usings.cs b/day08/day08.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day08/day08.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day08/day08.test/day08.test.csproj b/day08/day08.test/day08.test.csproj new file mode 100644 index 0000000..4b5b3c7 --- /dev/null +++ b/day08/day08.test/day08.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day08/day08.test/testdata.txt b/day08/day08.test/testdata.txt new file mode 100644 index 0000000..6557024 --- /dev/null +++ b/day08/day08.test/testdata.txt @@ -0,0 +1,5 @@ +30373 +25512 +65332 +33549 +35390 \ No newline at end of file diff --git a/day08/day08/Problem.cs b/day08/day08/Problem.cs new file mode 100644 index 0000000..72eb1bc --- /dev/null +++ b/day08/day08/Problem.cs @@ -0,0 +1,164 @@ +namespace day08; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var nrLines = lines.Length; + var nrColumns = lines[0].Length; + var visibleTrees = 0; + visibleTrees += 4;//corners + HashSet<(int, int)> innerTrees = new(); + + //scan lines + for (int i = 1; i < nrLines - 1; i++) + { + visibleTrees += 2; + var start = int.Parse(lines[i][0].ToString()); + var end = int.Parse(lines[i][nrColumns - 1].ToString()); + + //start to end + for (int j = 1; j < nrColumns - 1; j++) + { + var currentValue = int.Parse(lines[i][j].ToString()); + if (currentValue > start) + { + innerTrees.Add(new(i, j)); + start = currentValue; + } + } + //end to start + for (int j = nrColumns - 2; j > 0; j--) + { + var currentValue = int.Parse(lines[i][j].ToString()); + if (currentValue > end) + { + innerTrees.Add(new(i, j)); + end = currentValue; + } + } + } + + //scan columns + for (int i = 1; i < nrColumns - 1; i++) + { + visibleTrees += 2; + var start = int.Parse(lines[0][i].ToString()); + var end = int.Parse(lines[nrLines - 1][i].ToString()); + + //start to end + for (int j = 1; j < nrLines - 1; j++) + { + var currentValue = int.Parse(lines[j][i].ToString()); + if (currentValue > start) + { + innerTrees.Add(new(j, i)); + start = currentValue; + } + } + //end to start + for (int j = nrLines - 2; j > 0; j--) + { + var currentValue = int.Parse(lines[j][i].ToString()); + if (currentValue > end) + { + innerTrees.Add(new(j, i)); + end = currentValue; + } + } + } + + visibleTrees += innerTrees.Count; + // System.Console.WriteLine(visibleTrees); + + + Result1 = visibleTrees.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var nrLines = lines.Length; + var nrColumns = lines[0].Length; + + // PART 2 - using matrix + //populate + var martrix = new int[nrLines, nrColumns]; + for (int i = 0; i < nrLines; i++) + { + for (int j = 0; j < nrColumns; j++) + { + martrix[i, j] = int.Parse(lines[i][j].ToString()); + } + } + //scan inner tree score + var maxCellScore = 0; + for (int i = 1; i < nrLines - 1; i++) + { + for (int j = 1; j < nrColumns - 1; j++) + { + if (i == 3 && j == 2) + System.Diagnostics.Debugger.Break(); + + var currentValue = martrix[i, j]; + //scan up + var scoreUp = 0; + for (int up = i - 1; up >= 0; up--) + { + var testValue = martrix[up, j]; + scoreUp++; + if (testValue >= currentValue) + { + break; + } + } + //scan down + var scoreDown = 0; + for (int down = i + 1; down < nrLines; down++) + { + var testValue = martrix[down, j]; + scoreDown++; + if (testValue >= currentValue) + { + break; + } + } + //scan left + var scoreLeft = 0; + for (int left = j - 1; left >= 0; left--) + { + var testValue = martrix[i, left]; + scoreLeft++; + if (testValue >= currentValue) + { + break; + } + } + //scan right + var scoreRight = 0; + for (int right = j + 1; right < nrColumns; right++) + { + var testValue = martrix[i, right]; + scoreRight++; + if (testValue >= currentValue) + { + break; + } + } + + var cellScore = scoreUp * scoreDown * scoreLeft * scoreRight; + maxCellScore = Math.Max(cellScore, maxCellScore); + } + } + // System.Console.WriteLine($"maxCellScore: {maxCellScore}"); + //8 + //327180 - PERFECT! + + Result2 = maxCellScore.ToString(); + } +} diff --git a/day08/day08/Program.cs b/day08/day08/Program.cs new file mode 100644 index 0000000..4917f80 --- /dev/null +++ b/day08/day08/Program.cs @@ -0,0 +1,16 @@ +namespace day08; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day08/day08/day08.csproj b/day08/day08/day08.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day08/day08/day08.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day08/day08/input.txt b/day08/day08/input.txt new file mode 100644 index 0000000..9909f8d --- /dev/null +++ b/day08/day08/input.txt @@ -0,0 +1,99 @@ +301220120123412411222431204050154502352345215611331265331250145342122214525502214010044420343123123 +212320323343022012341342154350405334001503310300211115153234405042152322215224432102400231113311111 +201121301211224101311542432232543306541420361630235333011410624063304221040115102553044222124011231 +232202332000223341510415415041456543552366532665005356434300206166046103153010034420344343011033113 +210314434121343443320133105330346640420462134535200335545300063363254665242325230054401312222330003 +230214144101224050540112215100230300363531055535606540515103053341534215435154012112140240124100110 +231101440201215435252051416446206332423151420012651331143355655244262555053300034015013244122130030 +214222212324200401052120065613545410604234254167572224245015316613164134265153313214432220442033121 +010101140402334554220203222036634231512152221455263551635633346541265223541540132045335333002223424 +141224023202512320500606623246021536434116717372527356442422357712253035560552010313145410243214244 +342313244142203024440112330041036065142245413435573537671475271244610245022435212200405455551031300 +400412431024553054563062232450106636227551743332536773246216563237746040260223025405240105550211342 +141411114240054115626641115664417124644446553167127275573572277534716362414652422624302412000344204 +304244002433112544632613515265757653216235741254644271315654143447247446415244144112322551315312440 +034412130253154014325430531636135646423361675474554354114661252723134131331331364550211025331005110 +203230120341502446443342636426563227647672423846477226654522546745461257167105415103340235011202102 +000304220335434256006236536157317262616265763646677874377378263627235146376615515544066624323231543 +101323340335206434552203561646466267426825854776848224328252384531177377727463300325223111432452044 +443203522336150155435544744243555565545237722358736446652663532873525636261412225525550006103302105 +024402111202046625261447262172117482763754324238438534828367456666385662441762475663425231012052231 +304102502005006215165124145477583756557534848357388484458683773276743654452221742726125603631535221 +102242345301310562362655166723276388782224434488345643223328875357434577377774571124062514515225323 +243240452045506406233373246572828585355877339635749687859248246824648243733613635453456402505250303 +012352100012020202464336343645745643432459668843833863555554453734885388527435724644214236030032234 +502301551613053433631262457468258867289345397685878634954795338424484872426226353756723364155214515 +423041536552451365166244244533646822743993898794997445777675763398844356245712374176524561556305525 +425254640333051274352217364867636553657469538835745385349436985448743264485283366446114460665235412 +451305136116044364536433362258776588858395555558784748933645435747556548238346672563734344020454302 +432303643553065262322344228232565576689647769594849965393545794453967722354542675575263552410143115 +134544203161553255673562273655895763938858688958546785546995776997839965834382885435545631503335420 +555120002034333741674266784562695566888447446849894657668489395353895595526886884344327466141516541 +513443021302125256763465382844658763845358758869688948575985943473999357685734374175371446220146233 +233366010551721127328385236556377437634587845849877758459689687794745477428788742731316465140405213 +553011226633221264468324542499436483854879476698495899976485685488773948962325655755266442362003543 +312310355415566137337775829643373677544476849477957567497649568966978435833576736386411214630355151 +553145403544542737764542375578459459765676558566476444687477445946459378969263463861117325515431032 +536600400372417274463258586446436786877854445766879776549484448887448579549836737426771156120411052 +030621320724121554684336878497569899885854988855858555775456559646495997979468273647347456245100543 +545015312153425765287374339999948784855487886865776557656565676778594554989747852238614427623334041 +203005461166615125245248633779856478585597855957589689986888656699549686966355478473725534436206000 +552104352652311173347625849374448596777558588767888585799589875757945995549567776384722373626201524 +103604131421156167438445367445944478744687879597557966758786897455674875666365253527343435256603601 +300251364451465528673586486838569558457965667868668568797565799949548765587445748556373652351606135 +203613231642774436372333986973765865968569869659668887695588756978695547464449478577546236167206025 +000526564661714825335338489687486957856857855999788768958878987799494866538374633368677562673506424 +515644525376577475566446984796979687487766955689666777875898796699874589553539884845683175752360631 +221333616257462253823256375979645755896686997869696867698969958844999687686476364354576477345551111 +105222627452134822874253968777797786579655789896697888689986866976775779378896326264363317162751623 +162663173774176522666878887636864568989556887778997867979686869994994668955878548843786742723736203 +532212411613465674686254989747549989687685879666668989986756655657544797785388372436622767147424660 +061430341565238668884894448998884968886585676968898898887797795594859978795536965546586321556760355 +204541545567555653452864338665675969797686696989669999697778587687445456986538478322446257552365541 +655210032533533474674648398796577485555756797879766896878759679897748887646963922274775445666332035 +053321357461466882342436934979474474786699989987686798866969688869574558588835762723624774536431166 +425041634561312425882487676489694958795969757677677787687667668745846895668784782733254653163100605 +344310214433422228424464935784566975876698858796887769889968969647689677947447477245223663363264353 +012103166457117866567539896646478766886868755577978876887556878875797456794886958725574112516550415 +413644241335211836757687384748875888457579756795867975569679769875958466759557667477876467665436364 +162433152223317868882246466489998974769885556787595776775676788845855763393365742834482216655401026 +500614243747242223556575388534395464699869895767665788787956594678957798795886862225721534637646212 +242634342176667133277463595457877478984767787799769898889775888858895875758637368336261313356414300 +223205560227474377478554997966367944497877689866899558856977656965547586747685382327221347441146226 +322455466216143484536844779897496757954488957957898966886586675678888653535576477832464231615155324 +242335461373333262738285294874587649485768768756859998965778556857697358467855263664166411126122653 +442153320312725352645222487595939346478865868447588576959689664564667987947863564283733267742015623 +314256435256635233868576887878636755678944665464484575684575697584575336547784452783535121441266154 +223210513276524633887828464489635943745697744976674678945746697677399465735288783524413443155052460 +414644344437711641625883235659985578977459597858484566679475486473855973896455735345552521314243015 +303253565166734271425285323787763975858945897789759985997698796347779944885385552472565572215360642 +554345026245552362643534848687345838937664445457956798786577433576566547626774284415241562551163504 +311535565216661455148884287865768434966933844685584479978489494757874552577566854667712125345561545 +415250611366327134655472756753545737584664446946696869669867693575365348285472261146676153654423343 +245134635554051122723564642433875435935979656663668837797668649877868784674366711177437413214613242 +550305433351016326452653747274646969964344344955633437473798845985852738832263655166223231013250350 +412424612302616576262646757668355434555989468964573354645759674644744382678666232347542030341661053 +242250452046136264165613485835446658933483399657658764964566438484376638324734716771116242431415343 +215351034333540431527612622887846533476959369569746679337488463558585763464275533366551552100042055 +435431152542541137277441543722662552265876998963863345653536848472468446825623116641634431511341415 +512310146424650645726632222733373758536677539594973344357244627586436388227315222723436261011354444 +415342343465665344577661441528646685383427283566766246753572785343237264536223626355350051400140114 +241050242115325145031526345615255855442353746482385388835847843772354575412177127416310323254520420 +020220124435411053633257436463635336832525634734264453487345354485334651724244114546332526244014343 +233144204333151340325721264561431226263673564625645257644453365842865136737725510345534241014450104 +214445105522101254615065716656473235246624687543865265286684547535626265545173540645424255433043332 +131141005503150612140634466735217613138345322342853334247734784516716553114671206254014513103241500 +120132523034235121510330646154142646314331362452535865757484632521317751341716362446121030453315304 +222332342104255141541516053742767376342422671752664587373155226235757465552063266050454310555023234 +130022331402524533534126360254271165656147565354323324127344143267561232655640150546201542425232423 +041244331331204304551224525323327646371114744734661445454712776141442460245244062010323033300223040 +314114011311133543043561246666161424252355464267753775116255217554737010132161163160333313105310431 +241411310012501313224133414363533552666555416611756217364167127132203511115524044001111200411313443 +214302012402443103350331642331524446633763473467453377136566732405003511614151100044055214231314311 +010202242015444310420164245052526156300412151526245266534126364115514456545426434302254122342301411 +011423214303322230335200221004343440314264121472144246346134341155334411654112313203311044301330344 +301224314420311045034445523602316023152013003056146213152100641500545520504415031222210033304041411 +220214142234023331303304444234306015540260423514533053233166213614214141332141350123320443304043021 +012034313114122310325254321150626562505200402655111220563433533535445241355033442330140121212324203 +132300421231302002541021054032536231430015654305433356436004156146330254151224453535144411201021112 +011201113143220302144232532235500205436316601263264003140631445266055502252414045114101420043032302 \ No newline at end of file diff --git a/day08/problem.md b/day08/problem.md new file mode 100644 index 0000000..a58b7df --- /dev/null +++ b/day08/problem.md @@ -0,0 +1,75 @@ +--- Day 8: Treetop Tree House --- +The expedition comes across a peculiar patch of tall trees all planted carefully in a grid. The Elves explain that a previous expedition planted these trees as a reforestation effort. Now, they're curious if this would be a good location for a tree house. + +First, determine whether there is enough tree cover here to keep a tree house hidden. To do this, you need to count the number of trees that are visible from outside the grid when looking directly along a row or column. + +The Elves have already launched a quadcopter to generate a map with the height of each tree (your puzzle input). For example: + +30373 +25512 +65332 +33549 +35390 +Each tree is represented as a single digit whose value is its height, where 0 is the shortest and 9 is the tallest. + +A tree is visible if all of the other trees between it and an edge of the grid are shorter than it. Only consider trees in the same row or column; that is, only look up, down, left, or right from any given tree. + +All of the trees around the edge of the grid are visible - since they are already on the edge, there are no trees to block the view. In this example, that only leaves the interior nine trees to consider: + +The top-left 5 is visible from the left and top. (It isn't visible from the right or bottom since other trees of height 5 are in the way.) +The top-middle 5 is visible from the top and right. +The top-right 1 is not visible from any direction; for it to be visible, there would need to only be trees of height 0 between it and an edge. +The left-middle 5 is visible, but only from the right. +The center 3 is not visible from any direction; for it to be visible, there would need to be only trees of at most height 2 between it and an edge. +The right-middle 3 is visible from the right. +In the bottom row, the middle 5 is visible, but the 3 and 4 are not. +With 16 trees visible on the edge and another 5 visible in the interior, a total of 21 trees are visible in this arrangement. + +Consider your map; how many trees are visible from outside the grid? + +Your puzzle answer was 1672. + +--- Part Two --- +Content with the amount of tree cover available, the Elves just need to know the best spot to build their tree house: they would like to be able to see a lot of trees. + +To measure the viewing distance from a given tree, look up, down, left, and right from that tree; stop if you reach an edge or at the first tree that is the same height or taller than the tree under consideration. (If a tree is right on the edge, at least one of its viewing distances will be zero.) + +The Elves don't care about distant trees taller than those found by the rules above; the proposed tree house has large eaves to keep it dry, so they wouldn't be able to see higher than the tree house anyway. + +In the example above, consider the middle 5 in the second row: + +30373 +25512 +65332 +33549 +35390 +Looking up, its view is not blocked; it can see 1 tree (of height 3). +Looking left, its view is blocked immediately; it can see only 1 tree (of height 5, right next to it). +Looking right, its view is not blocked; it can see 2 trees. +Looking down, its view is blocked eventually; it can see 2 trees (one of height 3, then the tree of height 5 that blocks its view). +A tree's scenic score is found by multiplying together its viewing distance in each of the four directions. For this tree, this is 4 (found by multiplying 1 * 1 * 2 * 2). + +However, you can do even better: consider the tree of height 5 in the middle of the fourth row: + +30373 +25512 +65332 +33549 +35390 +Looking up, its view is blocked at 2 trees (by another tree with a height of 5). +Looking left, its view is not blocked; it can see 2 trees. +Looking down, its view is also not blocked; it can see 1 tree. +Looking right, its view is blocked at 2 trees (by a massive tree of height 9). +This tree's scenic score is 8 (2 * 2 * 1 * 2); this is the ideal spot for the tree house. + +Consider each tree on your map. What is the highest scenic score possible for any tree? + +Your puzzle answer was 327180. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day09/day09.test/UnitTestProblem.cs b/day09/day09.test/UnitTestProblem.cs new file mode 100644 index 0000000..a25c36d --- /dev/null +++ b/day09/day09.test/UnitTestProblem.cs @@ -0,0 +1,31 @@ +namespace day09.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("13"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("1"); + } + + [Fact] + public void TestProblem2larger() + { + var problem = new Problem(); + problem.ResolvePart2("testdata_large.txt"); + + problem.Result2.Should().Be("36"); + } +} \ No newline at end of file diff --git a/day09/day09.test/Usings.cs b/day09/day09.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day09/day09.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day09/day09.test/day09.test.csproj b/day09/day09.test/day09.test.csproj new file mode 100644 index 0000000..7998b13 --- /dev/null +++ b/day09/day09.test/day09.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day09/day09.test/testdata.txt b/day09/day09.test/testdata.txt new file mode 100644 index 0000000..cbea2b3 --- /dev/null +++ b/day09/day09.test/testdata.txt @@ -0,0 +1,8 @@ +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 \ No newline at end of file diff --git a/day09/day09.test/testdata_large.txt b/day09/day09.test/testdata_large.txt new file mode 100644 index 0000000..c1eba0a --- /dev/null +++ b/day09/day09.test/testdata_large.txt @@ -0,0 +1,8 @@ +R 5 +U 8 +L 8 +D 3 +R 17 +D 10 +L 25 +U 20 \ No newline at end of file diff --git a/day09/day09/Problem.cs b/day09/day09/Problem.cs new file mode 100644 index 0000000..ca9f989 --- /dev/null +++ b/day09/day09/Problem.cs @@ -0,0 +1,152 @@ +namespace day09; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var tailPositions = new HashSet<(int, int)>(); + tailPositions.Add((0, 0));//start position + var currentHeadPos = (x: 0, y: 0); + var knots = new List<(int x, int y)>(); + // nr of knots + // PART 1 + var knotsNo = 1; + knots.Add(currentHeadPos); + for (int i = 0; i < knotsNo; i++) + { + knots.Add((0, 0)); + } + foreach (var line in lines) + { + var linecmd = line.Split(" "); + var direction = linecmd[0]; + var tiles = int.Parse(linecmd[1]); + // System.Console.WriteLine($"{direction} {tiles}"); + for (int i = 0; i < tiles; i++) + { + switch (direction) + { + case "U": + currentHeadPos = (currentHeadPos.x, currentHeadPos.y - 1); + break; + case "D": + currentHeadPos = (currentHeadPos.x, currentHeadPos.y + 1); + break; + case "L": + currentHeadPos = (currentHeadPos.x - 1, currentHeadPos.y); + break; + case "R": + currentHeadPos = (currentHeadPos.x + 1, currentHeadPos.y); + break; + default: + throw new ArgumentException($"command {direction} not supported", nameof(direction)); + } + knots[0] = currentHeadPos; + + for (int j = 0; j < knotsNo; j++) + { + var firstKnot = knots[j]; + var secondKnot = knots[j + 1]; + AdjustTailPos(ref firstKnot, ref secondKnot); + knots[j + 1] = secondKnot; + } + tailPositions.Add(knots.Last());//add tail pos + } + } + // get # of unique positions visited by the tail - T + // System.Console.WriteLine($"tail visited positions {tailPositions.Count}"); + // P1 + //5710 + + Result1 = tailPositions.Count.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var tailPositions = new HashSet<(int, int)>(); + tailPositions.Add((0, 0));//start position + var currentHeadPos = (x: 0, y: 0); + var knots = new List<(int x, int y)>(); + // nr of knots + //PART2 + var knotsNo = 9; + knots.Add(currentHeadPos); + for (int i = 0; i < knotsNo; i++) + { + knots.Add((0, 0)); + } + foreach (var line in lines) + { + var linecmd = line.Split(" "); + var direction = linecmd[0]; + var tiles = int.Parse(linecmd[1]); + // System.Console.WriteLine($"{direction} {tiles}"); + for (int i = 0; i < tiles; i++) + { + switch (direction) + { + case "U": + currentHeadPos = (currentHeadPos.x, currentHeadPos.y - 1); + break; + case "D": + currentHeadPos = (currentHeadPos.x, currentHeadPos.y + 1); + break; + case "L": + currentHeadPos = (currentHeadPos.x - 1, currentHeadPos.y); + break; + case "R": + currentHeadPos = (currentHeadPos.x + 1, currentHeadPos.y); + break; + default: + throw new ArgumentException($"command {direction} not supported", nameof(direction)); + } + knots[0] = currentHeadPos; + + for (int j = 0; j < knotsNo; j++) + { + var firstKnot = knots[j]; + var secondKnot = knots[j + 1]; + AdjustTailPos(ref firstKnot, ref secondKnot); + knots[j + 1] = secondKnot; + } + tailPositions.Add(knots.Last());//add tail pos + } + } + // get # of unique positions visited by the tail - T + // System.Console.WriteLine($"tail visited positions {tailPositions.Count}"); + // P2 + //2259 + + Result2 = tailPositions.Count.ToString(); + } + + public static void AdjustTailPos(ref (int x, int y) headPos, ref (int x, int y) tailPos) + { + var dX = headPos.x - tailPos.x; + var dY = headPos.y - tailPos.y; + if (Math.Abs(dX) > 1 || Math.Abs(dY) > 1) + { + if (Math.Abs(dX) * Math.Abs(dY) > 1) + { + //diagonal + tailPos = ( + tailPos.x + Math.Sign(dX), + tailPos.y + Math.Sign(dY) + ); + } + else + { + tailPos = ( + tailPos.x + (Math.Abs(dX) > 0 ? (dX - Math.Sign(dX) * 1) : 0), + tailPos.y + (Math.Abs(dY) > 0 ? (dY - Math.Sign(dY) * 1) : 0) + ); + } + } + } +} diff --git a/day09/day09/Program.cs b/day09/day09/Program.cs new file mode 100644 index 0000000..fee8803 --- /dev/null +++ b/day09/day09/Program.cs @@ -0,0 +1,16 @@ +namespace day09; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + } +} diff --git a/day09/day09/day09.csproj b/day09/day09/day09.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day09/day09/day09.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day09/day09/input.txt b/day09/day09/input.txt new file mode 100644 index 0000000..c206ba3 --- /dev/null +++ b/day09/day09/input.txt @@ -0,0 +1,2000 @@ +R 2 +L 2 +D 2 +U 2 +R 2 +D 2 +L 2 +D 2 +U 2 +L 2 +D 1 +R 1 +D 2 +R 2 +U 1 +R 1 +U 2 +R 1 +L 2 +D 2 +L 1 +U 1 +L 1 +D 1 +R 1 +L 2 +U 2 +R 2 +U 1 +R 2 +L 2 +D 1 +U 1 +D 2 +L 1 +U 1 +L 1 +D 1 +U 1 +D 1 +L 2 +D 2 +U 2 +L 2 +U 1 +R 2 +D 2 +L 1 +R 1 +U 1 +R 1 +L 1 +U 2 +D 1 +U 2 +R 1 +U 1 +R 2 +D 2 +R 2 +U 2 +D 2 +U 2 +L 1 +D 2 +R 1 +L 2 +D 2 +R 2 +L 2 +U 2 +L 2 +R 1 +D 1 +R 1 +L 2 +D 1 +L 2 +R 1 +U 1 +R 1 +U 1 +L 2 +U 1 +D 2 +R 1 +L 1 +D 1 +R 1 +L 2 +R 2 +L 2 +R 1 +L 1 +D 1 +L 1 +R 1 +D 2 +U 1 +D 2 +R 1 +D 1 +U 1 +L 1 +R 1 +D 2 +R 2 +L 2 +R 1 +L 1 +R 1 +U 3 +L 2 +R 3 +L 1 +R 1 +L 2 +D 1 +U 3 +L 1 +R 3 +U 1 +L 2 +U 2 +D 2 +R 2 +D 1 +L 2 +U 1 +R 1 +L 3 +R 2 +L 3 +R 2 +L 2 +D 2 +U 3 +R 2 +L 1 +R 2 +U 1 +D 2 +U 3 +D 1 +U 3 +L 1 +R 3 +D 2 +R 1 +L 2 +D 1 +L 1 +D 3 +U 2 +L 3 +R 1 +U 3 +L 1 +R 2 +U 3 +D 2 +U 3 +L 3 +R 1 +L 2 +R 2 +D 3 +L 1 +D 3 +R 3 +L 1 +U 1 +D 1 +L 3 +D 1 +U 2 +D 3 +U 3 +L 1 +U 2 +D 1 +R 3 +D 1 +R 1 +L 2 +U 1 +R 1 +L 1 +U 3 +D 3 +U 3 +R 1 +D 3 +U 1 +L 2 +R 2 +U 2 +R 1 +D 3 +L 1 +D 2 +U 2 +R 2 +D 2 +R 3 +L 2 +R 1 +L 3 +D 3 +R 1 +L 1 +U 3 +R 1 +D 3 +R 3 +D 2 +U 2 +R 2 +D 2 +U 3 +D 2 +R 1 +U 2 +L 3 +D 1 +L 2 +U 1 +D 1 +U 4 +R 4 +U 4 +D 4 +U 3 +D 1 +R 4 +L 1 +D 2 +R 3 +U 1 +R 2 +D 2 +U 4 +R 3 +D 2 +L 1 +U 4 +D 3 +U 1 +D 4 +L 2 +U 3 +D 4 +R 3 +L 2 +D 4 +L 2 +R 3 +U 2 +R 2 +U 1 +L 3 +R 3 +L 3 +U 4 +R 4 +U 2 +R 3 +U 1 +L 3 +D 4 +L 4 +R 4 +D 3 +L 4 +R 1 +U 4 +D 3 +R 3 +U 1 +L 4 +U 2 +L 2 +D 4 +U 3 +R 1 +U 2 +D 4 +U 4 +D 4 +U 1 +L 4 +R 3 +U 2 +R 1 +L 4 +D 4 +U 3 +R 2 +L 2 +U 3 +L 1 +R 1 +L 1 +U 4 +L 1 +R 3 +U 1 +R 1 +D 2 +R 2 +L 4 +D 1 +L 2 +R 1 +D 1 +L 3 +D 3 +U 4 +R 2 +L 4 +U 2 +L 1 +R 3 +U 3 +L 2 +R 2 +D 2 +R 3 +U 4 +L 1 +U 3 +L 3 +U 1 +R 1 +L 2 +D 3 +L 5 +D 2 +U 2 +D 4 +R 2 +L 3 +U 3 +R 1 +U 4 +D 1 +R 2 +U 1 +L 5 +R 4 +D 5 +R 5 +D 2 +U 2 +L 5 +D 2 +U 3 +R 2 +L 4 +D 5 +L 4 +R 4 +U 5 +R 2 +U 5 +L 1 +D 2 +L 3 +U 4 +D 2 +U 2 +L 3 +R 4 +U 4 +R 5 +L 1 +D 2 +U 4 +D 5 +L 5 +R 4 +U 3 +R 2 +U 5 +L 3 +U 5 +R 3 +U 2 +R 2 +D 3 +R 2 +L 2 +D 4 +R 4 +U 3 +R 3 +D 5 +R 2 +U 3 +L 5 +R 1 +U 5 +D 4 +R 3 +D 5 +U 1 +R 4 +L 5 +D 1 +U 3 +L 4 +U 3 +R 3 +D 5 +U 5 +D 5 +L 5 +U 4 +D 5 +L 3 +R 3 +D 4 +U 2 +L 5 +R 1 +U 5 +L 4 +U 4 +D 5 +R 4 +L 1 +U 2 +D 2 +L 1 +R 2 +D 4 +R 5 +L 3 +R 4 +D 4 +L 4 +R 2 +L 1 +D 3 +L 3 +R 2 +D 3 +R 5 +D 2 +U 4 +D 5 +L 1 +U 3 +D 3 +U 6 +L 1 +R 1 +L 4 +R 6 +L 1 +R 1 +D 2 +U 6 +R 1 +U 3 +R 6 +U 1 +R 1 +L 3 +D 5 +R 6 +L 6 +R 1 +U 2 +R 1 +L 5 +R 5 +D 6 +R 4 +D 4 +R 1 +U 6 +R 4 +U 1 +R 5 +U 3 +L 5 +U 1 +R 5 +L 5 +D 5 +R 3 +L 5 +D 3 +L 2 +U 3 +R 1 +U 1 +D 4 +R 4 +L 2 +U 3 +L 1 +U 5 +L 5 +D 4 +R 6 +U 6 +L 5 +U 3 +R 3 +D 1 +U 6 +R 2 +L 4 +R 2 +L 5 +U 3 +D 1 +U 3 +R 1 +D 1 +L 3 +U 6 +L 5 +U 2 +L 3 +D 1 +L 3 +U 6 +L 4 +D 3 +R 4 +D 1 +L 4 +U 1 +R 6 +D 6 +R 5 +D 4 +R 4 +D 4 +U 6 +D 4 +L 3 +R 4 +L 5 +R 1 +D 6 +U 6 +D 2 +R 1 +L 6 +U 6 +L 5 +D 6 +U 4 +R 4 +D 3 +U 5 +D 6 +U 7 +L 5 +U 7 +R 6 +U 1 +L 6 +U 1 +R 2 +D 7 +R 4 +U 1 +R 6 +L 6 +D 4 +L 4 +U 4 +R 1 +D 7 +L 7 +D 7 +L 5 +D 1 +L 1 +U 2 +R 5 +D 5 +L 3 +U 5 +D 6 +L 4 +R 1 +U 6 +L 3 +D 6 +L 7 +D 6 +R 3 +U 7 +R 1 +D 6 +R 3 +U 7 +D 5 +U 1 +L 4 +U 3 +D 3 +U 3 +R 1 +L 2 +R 2 +L 1 +U 3 +D 5 +U 7 +D 1 +U 7 +L 4 +D 3 +U 4 +R 6 +D 2 +L 5 +R 7 +L 5 +R 1 +U 6 +R 7 +U 4 +D 3 +U 1 +L 1 +D 1 +U 6 +L 1 +U 1 +R 7 +L 4 +D 1 +U 2 +R 7 +L 7 +R 5 +U 4 +R 2 +L 7 +U 6 +R 5 +L 1 +R 3 +U 7 +D 7 +L 4 +R 1 +U 4 +R 1 +L 7 +D 4 +L 5 +D 7 +U 4 +L 5 +R 6 +U 1 +L 4 +R 6 +D 2 +L 1 +D 2 +U 4 +L 5 +U 5 +D 4 +U 7 +L 2 +D 3 +U 5 +R 7 +D 1 +R 7 +D 6 +U 4 +R 3 +D 5 +U 5 +D 8 +R 7 +L 7 +R 1 +D 5 +L 3 +R 1 +U 3 +R 6 +D 5 +R 6 +L 5 +D 7 +L 5 +R 2 +D 1 +R 7 +L 1 +D 3 +R 8 +L 5 +U 8 +R 6 +U 4 +D 2 +U 4 +D 5 +U 7 +D 5 +U 2 +D 3 +U 1 +R 4 +L 2 +R 4 +U 7 +R 8 +D 2 +U 3 +R 7 +D 2 +U 1 +D 6 +R 4 +L 4 +R 3 +D 8 +R 8 +U 7 +L 3 +U 7 +D 1 +U 6 +R 8 +L 1 +R 1 +D 8 +U 7 +L 3 +D 4 +L 4 +R 2 +L 6 +D 6 +L 4 +R 7 +D 8 +L 8 +U 8 +R 2 +L 6 +U 5 +D 2 +L 5 +U 1 +L 6 +D 6 +U 7 +L 2 +U 5 +R 6 +D 5 +L 8 +U 8 +R 1 +U 2 +L 3 +D 1 +L 3 +U 4 +D 3 +L 6 +R 9 +L 9 +U 9 +R 1 +D 4 +U 1 +L 3 +R 7 +U 7 +R 1 +U 1 +R 2 +D 4 +U 8 +L 7 +R 3 +U 8 +L 1 +R 1 +D 7 +U 3 +L 3 +U 8 +D 3 +L 1 +D 6 +L 3 +U 4 +D 3 +U 3 +L 3 +D 5 +L 6 +U 9 +L 1 +U 2 +L 3 +R 1 +L 9 +D 2 +U 1 +L 3 +R 9 +L 8 +R 2 +L 7 +D 4 +L 4 +R 2 +L 4 +R 8 +D 4 +L 2 +D 5 +R 8 +U 6 +L 9 +D 1 +L 6 +R 9 +D 4 +L 5 +U 5 +D 1 +U 3 +L 4 +U 2 +L 2 +R 2 +L 1 +R 7 +L 4 +D 4 +U 4 +L 1 +R 2 +D 6 +L 1 +U 8 +D 7 +R 5 +D 7 +R 7 +L 8 +U 8 +L 5 +D 7 +U 2 +D 2 +R 1 +U 2 +L 1 +R 1 +L 2 +D 1 +U 9 +L 9 +U 9 +R 1 +U 3 +R 7 +U 8 +R 1 +L 7 +D 1 +U 7 +R 9 +D 8 +R 2 +D 5 +L 5 +D 2 +L 6 +U 6 +R 1 +L 1 +D 2 +R 4 +L 3 +U 2 +R 5 +L 3 +R 6 +U 8 +R 1 +U 1 +R 7 +D 10 +R 2 +D 4 +R 3 +L 5 +D 1 +U 8 +R 1 +U 4 +D 6 +L 5 +U 8 +D 6 +L 6 +R 4 +L 9 +R 5 +U 6 +L 8 +U 6 +L 10 +D 4 +U 6 +L 8 +U 3 +R 3 +L 6 +U 1 +R 9 +D 8 +U 9 +R 5 +U 10 +R 8 +U 9 +L 7 +R 4 +D 7 +U 3 +L 5 +R 3 +D 9 +L 9 +U 6 +R 10 +L 2 +D 7 +U 8 +D 4 +L 3 +U 4 +R 2 +L 10 +D 4 +U 10 +R 7 +D 5 +R 7 +U 3 +L 10 +R 8 +L 7 +D 3 +L 6 +R 1 +L 2 +U 1 +R 1 +U 8 +R 5 +L 9 +R 9 +L 1 +D 4 +R 6 +U 7 +L 7 +R 3 +U 4 +D 2 +U 8 +L 5 +D 3 +L 6 +D 7 +L 2 +U 1 +R 6 +L 8 +D 9 +R 3 +U 4 +D 8 +L 5 +R 9 +L 1 +U 7 +L 5 +D 4 +U 5 +L 4 +R 4 +L 3 +U 11 +D 1 +L 10 +U 6 +L 5 +D 3 +U 8 +D 11 +L 8 +R 2 +U 5 +L 9 +D 3 +L 11 +R 2 +U 5 +L 7 +D 11 +R 8 +U 1 +L 10 +R 10 +L 9 +R 9 +L 8 +R 7 +D 3 +U 6 +R 11 +U 8 +D 4 +L 9 +U 3 +D 5 +L 4 +R 5 +D 7 +L 5 +U 10 +D 8 +L 3 +D 2 +U 9 +D 6 +L 3 +U 3 +D 8 +U 4 +R 1 +L 9 +U 4 +L 5 +D 10 +L 11 +U 6 +D 8 +L 5 +R 9 +L 2 +U 2 +L 10 +R 5 +U 6 +L 7 +R 7 +U 9 +D 6 +R 7 +D 8 +U 7 +R 6 +L 2 +D 6 +R 8 +L 5 +R 1 +L 10 +R 8 +U 11 +R 10 +L 10 +R 10 +L 4 +U 4 +D 9 +U 8 +R 5 +D 7 +U 7 +L 6 +D 4 +L 9 +R 2 +U 8 +D 2 +L 2 +D 2 +U 6 +L 2 +R 9 +U 10 +D 11 +U 3 +R 9 +U 1 +L 11 +R 7 +L 4 +R 5 +U 10 +L 3 +R 10 +L 10 +D 2 +L 9 +D 9 +L 6 +D 11 +R 10 +L 2 +R 4 +D 2 +R 4 +D 8 +L 3 +U 10 +R 4 +L 2 +U 1 +L 3 +R 1 +L 2 +R 3 +D 2 +L 2 +D 3 +R 5 +U 10 +L 12 +R 5 +D 5 +U 9 +L 9 +D 2 +L 8 +U 2 +L 11 +U 5 +L 8 +U 7 +R 4 +U 10 +D 4 +L 5 +R 3 +D 8 +R 12 +L 5 +U 9 +L 10 +R 5 +U 10 +R 1 +L 5 +U 6 +D 7 +L 12 +D 2 +R 12 +L 1 +U 11 +D 8 +R 12 +L 8 +U 3 +R 9 +L 8 +D 2 +L 10 +D 10 +R 4 +D 2 +R 11 +U 4 +R 10 +U 7 +L 7 +D 5 +U 5 +R 9 +D 10 +L 10 +U 1 +D 11 +U 4 +D 5 +U 5 +D 8 +U 2 +D 4 +R 4 +L 5 +U 10 +D 12 +R 9 +L 11 +R 9 +L 1 +D 9 +L 11 +D 12 +U 4 +R 7 +D 1 +U 3 +L 4 +U 9 +R 12 +D 1 +L 7 +U 7 +D 6 +U 1 +R 3 +L 7 +U 5 +L 2 +D 10 +R 12 +L 3 +U 7 +D 10 +L 5 +R 1 +U 9 +L 1 +D 11 +R 5 +L 2 +D 1 +U 3 +R 2 +L 3 +U 5 +L 3 +D 5 +R 10 +L 7 +R 12 +U 4 +D 3 +R 3 +L 2 +R 7 +U 4 +D 9 +U 7 +D 1 +R 9 +L 2 +U 6 +R 5 +D 3 +U 7 +R 12 +L 10 +D 11 +L 8 +U 12 +D 13 +U 9 +D 5 +U 4 +R 2 +L 3 +U 13 +R 4 +L 9 +U 4 +L 3 +U 9 +R 1 +D 6 +U 4 +D 3 +U 5 +R 5 +L 11 +R 8 +D 1 +U 4 +D 10 +R 5 +D 10 +U 3 +D 4 +R 1 +U 3 +R 13 +L 6 +D 8 +R 12 +L 4 +U 2 +L 13 +D 11 +L 4 +U 8 +L 10 +R 2 +D 8 +R 11 +L 2 +D 8 +R 8 +L 10 +U 10 +L 4 +D 9 +L 7 +D 11 +L 10 +U 13 +L 6 +U 7 +D 8 +L 3 +R 10 +L 14 +U 13 +L 11 +D 5 +R 8 +U 2 +D 9 +L 14 +U 7 +R 4 +U 1 +D 8 +U 8 +D 9 +L 2 +D 7 +R 1 +D 9 +R 2 +U 4 +D 8 +L 9 +R 6 +L 2 +R 11 +D 6 +L 5 +U 8 +L 4 +R 3 +D 5 +L 3 +U 9 +R 3 +U 1 +D 7 +R 1 +L 10 +U 1 +L 8 +U 11 +D 8 +U 12 +R 9 +L 5 +D 10 +L 2 +R 8 +D 10 +R 6 +D 1 +L 11 +D 8 +R 7 +L 14 +D 12 +L 11 +R 11 +U 9 +R 12 +D 10 +L 12 +R 4 +L 8 +D 2 +R 3 +L 14 +R 7 +U 10 +R 1 +L 6 +R 4 +D 11 +L 13 +R 12 +U 4 +L 12 +U 10 +D 8 +R 10 +D 9 +R 13 +L 2 +U 2 +D 7 +U 7 +R 3 +D 3 +R 13 +U 8 +R 10 +U 13 +D 14 +R 11 +D 7 +R 2 +U 5 +D 2 +L 6 +U 14 +L 10 +R 9 +U 11 +R 12 +D 5 +L 11 +R 12 +U 11 +R 8 +L 2 +D 14 +U 3 +D 9 +U 5 +L 4 +U 5 +L 6 +D 3 +L 1 +R 10 +L 4 +D 12 +U 15 +L 5 +D 11 +L 15 +D 10 +L 14 +U 1 +L 14 +D 6 +R 6 +U 9 +R 1 +L 7 +D 11 +U 12 +D 2 +R 7 +L 2 +D 13 +U 13 +R 6 +L 3 +D 3 +R 11 +U 3 +D 3 +U 11 +L 10 +U 7 +R 7 +D 9 +U 10 +R 11 +U 12 +D 11 +R 11 +U 2 +R 2 +D 9 +R 12 +D 1 +L 11 +R 1 +U 2 +R 14 +L 4 +R 1 +D 12 +R 7 +U 12 +L 2 +U 5 +D 7 +R 15 +D 5 +L 9 +D 7 +R 10 +U 12 +D 10 +R 11 +D 5 +U 10 +R 2 +U 11 +R 3 +U 6 +D 14 +U 11 +D 5 +L 8 +D 6 +L 2 +U 2 +L 14 +R 8 +U 15 +L 10 +D 1 +R 4 +L 8 +D 7 +L 15 +U 10 +D 14 +U 9 +L 7 +R 13 +U 11 +R 15 +L 11 +R 2 +L 11 +R 14 +L 1 +D 10 +L 2 +U 7 +L 9 +D 12 +R 2 +L 4 +U 4 +R 9 +L 6 +R 13 +D 1 +U 13 +R 7 +D 3 +R 14 +L 12 +D 15 +R 16 +L 7 +R 2 +U 3 +R 9 +U 10 +D 6 +U 7 +L 11 +D 12 +L 16 +R 12 +D 10 +U 16 +D 9 +U 14 +L 14 +U 11 +D 14 +L 14 +D 10 +L 3 +D 10 +U 6 +D 11 +L 8 +U 4 +D 1 +U 5 +D 5 +L 4 +U 8 +R 3 +D 12 +U 4 +R 8 +D 6 +U 8 +D 2 +U 12 +L 6 +D 12 +R 7 +D 6 +U 7 +D 12 +L 3 +R 2 +L 12 +R 13 +U 16 +L 6 +D 8 +U 13 +R 14 +D 4 +U 7 +D 1 +R 4 +D 13 +R 10 +D 7 +R 11 +L 6 +U 6 +R 7 +L 8 +D 2 +L 11 +U 3 +L 12 +U 4 +D 11 +U 8 +D 10 +U 1 +R 12 +U 1 +L 15 +R 15 +D 2 +L 8 +D 13 +L 3 +R 8 +U 14 +R 5 +U 3 +D 15 +U 7 +D 1 +L 6 +D 8 +U 13 +R 6 +L 6 +D 3 +L 9 +D 17 +U 8 +R 16 +L 6 +D 9 +U 3 +L 10 +R 13 +L 14 +U 8 +R 7 +U 12 +D 14 +R 1 +D 3 +L 11 +R 8 +D 9 +R 17 +D 5 +R 17 +U 8 +L 10 +D 7 +U 4 +D 16 +L 9 +D 1 +L 16 +R 7 +L 1 +R 11 +U 10 +R 2 +U 10 +L 15 +U 10 +R 2 +D 11 +U 12 +L 15 +U 4 +D 2 +R 4 +U 2 +L 11 +R 16 +U 10 +R 4 +D 9 +U 7 +D 2 +R 10 +D 14 +L 10 +U 9 +R 7 +D 3 +R 7 +L 3 +U 15 +D 13 +L 17 +R 12 +U 13 +D 16 +U 13 +R 13 +U 14 +L 16 +U 7 +D 2 +R 11 +U 17 +D 9 +R 12 +U 16 +L 11 +R 3 +U 9 +L 6 +D 2 +U 1 +D 7 +L 1 +U 7 +D 8 +U 11 +L 4 +R 6 +L 2 +U 12 +L 13 +U 5 +L 17 +R 16 +D 10 +U 12 +L 7 +R 4 +U 8 +D 17 +R 13 +L 2 +D 5 +L 1 +R 2 +D 16 +U 9 +D 15 +L 8 +U 14 +R 9 +D 18 +U 16 +L 17 +U 9 +D 11 +U 17 +R 8 +D 17 +U 14 +D 8 +U 8 +R 8 +U 14 +R 5 +L 1 +R 3 +D 5 +U 10 +R 16 +U 18 +D 16 +U 11 +D 18 +U 13 +L 11 +D 2 +R 16 +D 15 +L 9 +D 12 +R 11 +L 8 +U 8 +R 10 +L 2 +D 6 +L 5 +D 9 +L 3 +D 1 +U 18 +D 12 +U 13 +L 6 +R 17 +D 10 +R 9 +L 6 +R 3 +U 1 +R 1 +U 6 +L 15 +U 8 +D 15 +U 14 +R 10 +L 6 +U 1 +L 12 +R 9 +D 13 +U 1 +L 16 +U 16 +L 13 +R 4 +U 3 +D 11 +L 12 +R 11 +U 17 +R 18 +L 4 +R 6 +L 18 +D 10 +L 16 +R 2 +D 4 +R 14 +D 11 +L 12 +R 7 +L 9 +U 12 +D 12 +R 4 +L 1 +D 14 +R 14 +L 3 +U 2 +L 6 +R 7 +D 6 +U 18 +L 17 +U 12 +R 12 +L 5 +D 13 +R 7 +D 8 +L 16 +D 13 +U 4 +D 3 +R 16 +L 9 +U 8 +D 15 +R 8 +L 12 +R 5 +L 1 +U 11 +D 11 +L 10 +U 7 +D 6 +L 15 +D 9 +R 10 +D 6 +U 14 +L 7 +U 19 +R 17 +L 12 +U 1 +L 9 +R 17 +D 12 +U 3 +L 15 +R 16 +D 15 +R 15 +L 1 +U 16 +R 19 +D 9 +L 16 +D 12 +R 8 +L 2 +D 16 +L 17 +U 16 +D 9 +L 9 +U 8 +L 9 +R 16 +L 3 +D 8 +U 7 +D 10 +U 17 +R 2 +D 16 +R 6 +U 9 +R 4 +L 17 +D 10 +U 10 +L 14 +D 9 +R 8 +L 9 +R 18 +U 13 +L 16 +R 2 +U 16 +L 11 +U 4 +L 13 +R 8 +L 19 +U 4 +D 10 +R 10 +U 14 +R 13 +L 17 +U 17 +R 12 +D 18 +R 2 +D 5 +L 12 +U 6 +D 7 +R 9 +L 13 +D 15 +R 9 +U 16 +D 14 +R 8 +L 8 +U 10 +L 8 +D 18 +U 8 +D 9 +L 6 +R 8 +U 4 +D 14 +L 13 +D 4 +R 3 +U 13 +L 2 \ No newline at end of file diff --git a/day09/problem.md b/day09/problem.md new file mode 100644 index 0000000..5707836 --- /dev/null +++ b/day09/problem.md @@ -0,0 +1,683 @@ +--- Day 9: Rope Bridge --- +This rope bridge creaks as you walk along it. You aren't sure how old it is, or whether it can even support your weight. + +It seems to support the Elves just fine, though. The bridge spans a gorge which was carved out by the massive river far below you. + +You step carefully; as you do, the ropes stretch and twist. You decide to distract yourself by modeling rope physics; maybe you can even figure out where not to step. + +Consider a rope with a knot at each end; these knots mark the head and the tail of the rope. If the head moves far enough away from the tail, the tail is pulled toward the head. + +Due to nebulous reasoning involving Planck lengths, you should be able to model the positions of the knots on a two-dimensional grid. Then, by following a hypothetical series of motions (your puzzle input) for the head, you can determine how the tail will move. + +Due to the aforementioned Planck lengths, the rope must be quite short; in fact, the head (H) and tail (T) must always be touching (diagonally adjacent and even overlapping both count as touching): + +.... +.TH. +.... + +.... +.H.. +..T. +.... + +... +.H. (H covers T) +... +If the head is ever two steps directly up, down, left, or right from the tail, the tail must also move one step in that direction so it remains close enough: + +..... ..... ..... +.TH.. -> .T.H. -> ..TH. +..... ..... ..... + +... ... ... +.T. .T. ... +.H. -> ... -> .T. +... .H. .H. +... ... ... +Otherwise, if the head and tail aren't touching and aren't in the same row or column, the tail always moves one step diagonally to keep up: + +..... ..... ..... +..... ..H.. ..H.. +..H.. -> ..... -> ..T.. +.T... .T... ..... +..... ..... ..... + +..... ..... ..... +..... ..... ..... +..H.. -> ...H. -> ..TH. +.T... .T... ..... +..... ..... ..... +You just need to work out where the tail goes as the head follows a series of motions. Assume the head and the tail both start at the same position, overlapping. + +For example: + +R 4 +U 4 +L 3 +D 1 +R 4 +D 1 +L 5 +R 2 +This series of motions moves the head right four steps, then up four steps, then left three steps, then down one step, and so on. After each step, you'll need to update the position of the tail if the step means the head is no longer adjacent to the tail. Visually, these motions occur as follows (s marks the starting position as a reference point): + +== Initial State == + +...... +...... +...... +...... +H..... (H covers T, s) + +== R 4 == + +...... +...... +...... +...... +TH.... (T covers s) + +...... +...... +...... +...... +sTH... + +...... +...... +...... +...... +s.TH.. + +...... +...... +...... +...... +s..TH. + +== U 4 == + +...... +...... +...... +....H. +s..T.. + +...... +...... +....H. +....T. +s..... + +...... +....H. +....T. +...... +s..... + +....H. +....T. +...... +...... +s..... + +== L 3 == + +...H.. +....T. +...... +...... +s..... + +..HT.. +...... +...... +...... +s..... + +.HT... +...... +...... +...... +s..... + +== D 1 == + +..T... +.H.... +...... +...... +s..... + +== R 4 == + +..T... +..H... +...... +...... +s..... + +..T... +...H.. +...... +...... +s..... + +...... +...TH. +...... +...... +s..... + +...... +....TH +...... +...... +s..... + +== D 1 == + +...... +....T. +.....H +...... +s..... + +== L 5 == + +...... +....T. +....H. +...... +s..... + +...... +....T. +...H.. +...... +s..... + +...... +...... +..HT.. +...... +s..... + +...... +...... +.HT... +...... +s..... + +...... +...... +HT.... +...... +s..... + +== R 2 == + +...... +...... +.H.... (H covers T) +...... +s..... + +...... +...... +.TH... +...... +s..... +After simulating the rope, you can count up all of the positions the tail visited at least once. In this diagram, s again marks the starting position (which the tail also visited) and # marks other positions the tail visited: + +..##.. +...##. +.####. +....#. +s###.. +So, there are 13 positions the tail visited at least once. + +Simulate your complete hypothetical series of motions. How many positions does the tail of the rope visit at least once? + +Your puzzle answer was 5710. + +--- Part Two --- +A rope snaps! Suddenly, the river is getting a lot closer than you remember. The bridge is still there, but some of the ropes that broke are now whipping toward you as you fall through the air! + +The ropes are moving too quickly to grab; you only have a few seconds to choose how to arch your body to avoid being hit. Fortunately, your simulation can be extended to support longer ropes. + +Rather than two knots, you now must simulate a rope consisting of ten knots. One knot is still the head of the rope and moves according to the series of motions. Each knot further down the rope follows the knot in front of it using the same rules as before. + +Using the same series of motions as the above example, but with the knots marked H, 1, 2, ..., 9, the motions now occur as follows: + +== Initial State == + +...... +...... +...... +...... +H..... (H covers 1, 2, 3, 4, 5, 6, 7, 8, 9, s) + +== R 4 == + +...... +...... +...... +...... +1H.... (1 covers 2, 3, 4, 5, 6, 7, 8, 9, s) + +...... +...... +...... +...... +21H... (2 covers 3, 4, 5, 6, 7, 8, 9, s) + +...... +...... +...... +...... +321H.. (3 covers 4, 5, 6, 7, 8, 9, s) + +...... +...... +...... +...... +4321H. (4 covers 5, 6, 7, 8, 9, s) + +== U 4 == + +...... +...... +...... +....H. +4321.. (4 covers 5, 6, 7, 8, 9, s) + +...... +...... +....H. +.4321. +5..... (5 covers 6, 7, 8, 9, s) + +...... +....H. +....1. +.432.. +5..... (5 covers 6, 7, 8, 9, s) + +....H. +....1. +..432. +.5.... +6..... (6 covers 7, 8, 9, s) + +== L 3 == + +...H.. +....1. +..432. +.5.... +6..... (6 covers 7, 8, 9, s) + +..H1.. +...2.. +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +.H1... +...2.. +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +== D 1 == + +..1... +.H.2.. +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +== R 4 == + +..1... +..H2.. +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +..1... +...H.. (H covers 2) +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...1H. (1 covers 2) +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...21H +..43.. +.5.... +6..... (6 covers 7, 8, 9, s) + +== D 1 == + +...... +...21. +..43.H +.5.... +6..... (6 covers 7, 8, 9, s) + +== L 5 == + +...... +...21. +..43H. +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...21. +..4H.. (H covers 3) +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...2.. +..H1.. (H covers 4; 1 covers 3) +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...2.. +.H13.. (1 covers 4) +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...... +H123.. (2 covers 4) +.5.... +6..... (6 covers 7, 8, 9, s) + +== R 2 == + +...... +...... +.H23.. (H covers 1; 2 covers 4) +.5.... +6..... (6 covers 7, 8, 9, s) + +...... +...... +.1H3.. (H covers 2, 4) +.5.... +6..... (6 covers 7, 8, 9, s) +Now, you need to keep track of the positions the new tail, 9, visits. In this example, the tail never moves, and so it only visits 1 position. However, be careful: more types of motion are possible than before, so you might want to visually compare your simulated rope to the one above. + +Here's a larger example: + +R 5 +U 8 +L 8 +D 3 +R 17 +D 10 +L 25 +U 20 +These motions occur as follows (individual steps are not shown): + +== Initial State == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +...........H.............. (H covers 1, 2, 3, 4, 5, 6, 7, 8, 9, s) +.......................... +.......................... +.......................... +.......................... +.......................... + +== R 5 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +...........54321H......... (5 covers 6, 7, 8, 9, s) +.......................... +.......................... +.......................... +.......................... +.......................... + +== U 8 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +................H......... +................1......... +................2......... +................3......... +...............54......... +..............6........... +.............7............ +............8............. +...........9.............. (9 covers s) +.......................... +.......................... +.......................... +.......................... +.......................... + +== L 8 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +........H1234............. +............5............. +............6............. +............7............. +............8............. +............9............. +.......................... +.......................... +...........s.............. +.......................... +.......................... +.......................... +.......................... +.......................... + +== D 3 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.........2345............. +........1...6............. +........H...7............. +............8............. +............9............. +.......................... +.......................... +...........s.............. +.......................... +.......................... +.......................... +.......................... +.......................... + +== R 17 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +................987654321H +.......................... +.......................... +.......................... +.......................... +...........s.............. +.......................... +.......................... +.......................... +.......................... +.......................... + +== D 10 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +...........s.........98765 +.........................4 +.........................3 +.........................2 +.........................1 +.........................H + +== L 25 == + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +...........s.............. +.......................... +.......................... +.......................... +.......................... +H123456789................ + +== U 20 == + +H......................... +1......................... +2......................... +3......................... +4......................... +5......................... +6......................... +7......................... +8......................... +9......................... +.......................... +.......................... +.......................... +.......................... +.......................... +...........s.............. +.......................... +.......................... +.......................... +.......................... +.......................... + +Now, the tail (9) visits 36 positions (including s) at least once: + +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +.......................... +#......................... +#.............###......... +#............#...#........ +.#..........#.....#....... +..#..........#.....#...... +...#........#.......#..... +....#......s.........#.... +.....#..............#..... +......#............#...... +.......#..........#....... +........#........#........ +.........########......... +Simulate your complete series of motions on a larger rope with ten knots. How many positions does the tail of the rope visit at least once? + +Your puzzle answer was 2259. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day10/day10.test/UnitTestProblem.cs b/day10/day10.test/UnitTestProblem.cs new file mode 100644 index 0000000..68bafcc --- /dev/null +++ b/day10/day10.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day10.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("13140"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Length.Should().Be(246); + } +} \ No newline at end of file diff --git a/day10/day10.test/Usings.cs b/day10/day10.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day10/day10.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day10/day10.test/day10.test.csproj b/day10/day10.test/day10.test.csproj new file mode 100644 index 0000000..bd57c15 --- /dev/null +++ b/day10/day10.test/day10.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day10/day10.test/testdata.txt b/day10/day10.test/testdata.txt new file mode 100644 index 0000000..94cd0a8 --- /dev/null +++ b/day10/day10.test/testdata.txt @@ -0,0 +1,146 @@ +addx 15 +addx -11 +addx 6 +addx -3 +addx 5 +addx -1 +addx -8 +addx 13 +addx 4 +noop +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx -35 +addx 1 +addx 24 +addx -19 +addx 1 +addx 16 +addx -11 +noop +noop +addx 21 +addx -15 +noop +noop +addx -3 +addx 9 +addx 1 +addx -3 +addx 8 +addx 1 +addx 5 +noop +noop +noop +noop +noop +addx -36 +noop +addx 1 +addx 7 +noop +noop +noop +addx 2 +addx 6 +noop +noop +noop +noop +noop +addx 1 +noop +noop +addx 7 +addx 1 +noop +addx -13 +addx 13 +addx 7 +noop +addx 1 +addx -33 +noop +noop +noop +addx 2 +noop +noop +noop +addx 8 +noop +addx -1 +addx 2 +addx 1 +noop +addx 17 +addx -9 +addx 1 +addx 1 +addx -3 +addx 11 +noop +noop +addx 1 +noop +addx 1 +noop +noop +addx -13 +addx -19 +addx 1 +addx 3 +addx 26 +addx -30 +addx 12 +addx -1 +addx 3 +addx 1 +noop +noop +noop +addx -9 +addx 18 +addx 1 +addx 2 +noop +noop +addx 9 +noop +noop +noop +addx -1 +addx 2 +addx -37 +addx 1 +addx 3 +noop +addx 15 +addx -21 +addx 22 +addx -6 +addx 1 +noop +addx 2 +addx 1 +noop +addx -10 +noop +noop +addx 20 +addx 1 +addx 2 +addx 2 +addx -6 +addx -11 +noop +noop +noop \ No newline at end of file diff --git a/day10/day10/Problem.cs b/day10/day10/Problem.cs new file mode 100644 index 0000000..dd9f7d0 --- /dev/null +++ b/day10/day10/Problem.cs @@ -0,0 +1,99 @@ +namespace day10; + +using System.Text; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + private List lstCycle = new List{ + 20, 60, 100, 140, 180, 220 + }; + private int crtIdx = 0; + + StringBuilder sbRes2 = new(); + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var cycle = 0; + var regX = 1; + var sumSignal = 0; + // + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i]; + var lineParts = line.Split(" "); + var cmd = lineParts[0]; + switch (cmd) + { + case "noop": + cycle++; + sumSignal += DisplayForCycle(cycle, regX, i); + break; + case "addx": + cycle++; + sumSignal += DisplayForCycle(cycle, regX, i); + cycle++; + sumSignal += DisplayForCycle(cycle, regX, i); + regX += int.Parse(lineParts[1]); + break; + default: + throw new ArgumentException($"invalid cmd {cmd}"); + break; + } + } + // System.Console.WriteLine($"sumSignal: {sumSignal}"); + //13140 + //11720 + + Result1 = sumSignal.ToString(); + } + + public void ResolvePart2(string arg) + { + ResolvePart1(arg); + + Result2 = sbRes2.ToString(); + } + + public int DisplayForCycle(int cycle, int regX, int lineNo) + { + // + if (SpriteIntersect(regX, crtIdx)) + { + sbRes2.Append("#"); + // System.Console.Write("#"); + } + else + { + sbRes2.Append("."); + // System.Console.Write("."); + } + crtIdx++; + if (crtIdx % 40 == 0) + { + sbRes2.Append(Environment.NewLine); + // System.Console.WriteLine(""); + } + // + if (regX < -1) + { + //System.Console.WriteLine($"regX is less than zero. {regX}"); + } + if (lstCycle.Contains(cycle)) + { + //System.Console.WriteLine($"cycle: {cycle} X: {regX} ss:{cycle * regX} on lineNo: {lineNo}"); + return cycle * regX; + } + return 0; + } + + public bool SpriteIntersect(int regX, int crtIdx) + { + var m40 = regX % 40; + var c40 = crtIdx % 40; + return (c40 >= m40 - 1 && c40 <= m40 + 1); + } +} diff --git a/day10/day10/Program.cs b/day10/day10/Program.cs new file mode 100644 index 0000000..fe86954 --- /dev/null +++ b/day10/day10/Program.cs @@ -0,0 +1,18 @@ +namespace day10; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + //11720 + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + // ERCREPCJ + } +} diff --git a/day10/day10/day10.csproj b/day10/day10/day10.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day10/day10/day10.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day10/day10/input.txt b/day10/day10/input.txt new file mode 100644 index 0000000..32f57a4 --- /dev/null +++ b/day10/day10/input.txt @@ -0,0 +1,146 @@ +addx 1 +addx 4 +noop +noop +noop +noop +addx 6 +addx -1 +noop +addx 5 +noop +addx 5 +noop +noop +noop +addx 1 +addx 3 +addx 1 +addx 6 +addx -1 +noop +noop +noop +addx 7 +noop +addx -39 +noop +noop +noop +addx 7 +addx 3 +addx -2 +addx 2 +noop +addx 3 +addx 2 +addx 5 +addx 2 +addx -8 +addx 13 +noop +addx 3 +addx -2 +addx 2 +addx 5 +addx -31 +addx 36 +addx -2 +addx -36 +noop +noop +noop +addx 3 +addx 5 +addx 2 +addx -7 +addx 15 +addx -5 +addx 5 +addx 2 +addx 1 +addx 4 +noop +addx 3 +noop +addx 2 +addx -13 +addx -16 +addx 2 +addx 35 +addx -40 +noop +noop +addx 7 +noop +noop +noop +addx 5 +noop +addx 5 +addx 10 +addx -10 +noop +noop +noop +addx 3 +noop +addx 16 +addx -9 +noop +noop +noop +addx 3 +noop +addx 7 +addx -32 +addx 35 +addx -38 +addx 22 +addx 10 +addx -29 +addx 2 +noop +addx 3 +addx 5 +addx 2 +addx 2 +addx -12 +addx 13 +noop +noop +addx 7 +addx 5 +noop +noop +noop +addx 7 +addx -6 +addx 2 +addx 5 +addx -38 +addx 1 +noop +noop +addx 2 +noop +addx 3 +addx 5 +noop +addx 4 +addx -2 +addx 5 +addx 2 +addx 1 +noop +addx 4 +addx 4 +addx -14 +addx 16 +noop +addx -13 +addx 18 +addx -1 +noop +noop +noop \ No newline at end of file diff --git a/day10/problem.md b/day10/problem.md new file mode 100644 index 0000000..1627b0b --- /dev/null +++ b/day10/problem.md @@ -0,0 +1,323 @@ +--- Day 10: Cathode-Ray Tube --- +You avoid the ropes, plunge into the river, and swim to shore. + +The Elves yell something about meeting back up with them upriver, but the river is too loud to tell exactly what they're saying. They finish crossing the bridge and disappear from view. + +Situations like this must be why the Elves prioritized getting the communication system on your handheld device working. You pull it out of your pack, but the amount of water slowly draining from a big crack in its screen tells you it probably won't be of much immediate use. + +Unless, that is, you can design a replacement for the device's video system! It seems to be some kind of cathode-ray tube screen and simple CPU that are both driven by a precise clock circuit. The clock circuit ticks at a constant rate; each tick is called a cycle. + +Start by figuring out the signal being sent by the CPU. The CPU has a single register, X, which starts with the value 1. It supports only two instructions: + +addx V takes two cycles to complete. After two cycles, the X register is increased by the value V. (V can be negative.) +noop takes one cycle to complete. It has no other effect. +The CPU uses these instructions in a program (your puzzle input) to, somehow, tell the screen what to draw. + +Consider the following small program: + +noop +addx 3 +addx -5 +Execution of this program proceeds as follows: + +At the start of the first cycle, the noop instruction begins execution. During the first cycle, X is 1. After the first cycle, the noop instruction finishes execution, doing nothing. +At the start of the second cycle, the addx 3 instruction begins execution. During the second cycle, X is still 1. +During the third cycle, X is still 1. After the third cycle, the addx 3 instruction finishes execution, setting X to 4. +At the start of the fourth cycle, the addx -5 instruction begins execution. During the fourth cycle, X is still 4. +During the fifth cycle, X is still 4. After the fifth cycle, the addx -5 instruction finishes execution, setting X to -1. +Maybe you can learn something by looking at the value of the X register throughout execution. For now, consider the signal strength (the cycle number multiplied by the value of the X register) during the 20th cycle and every 40 cycles after that (that is, during the 20th, 60th, 100th, 140th, 180th, and 220th cycles). + +For example, consider this larger program: + +addx 15 +addx -11 +addx 6 +addx -3 +addx 5 +addx -1 +addx -8 +addx 13 +addx 4 +noop +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx 5 +addx -1 +addx -35 +addx 1 +addx 24 +addx -19 +addx 1 +addx 16 +addx -11 +noop +noop +addx 21 +addx -15 +noop +noop +addx -3 +addx 9 +addx 1 +addx -3 +addx 8 +addx 1 +addx 5 +noop +noop +noop +noop +noop +addx -36 +noop +addx 1 +addx 7 +noop +noop +noop +addx 2 +addx 6 +noop +noop +noop +noop +noop +addx 1 +noop +noop +addx 7 +addx 1 +noop +addx -13 +addx 13 +addx 7 +noop +addx 1 +addx -33 +noop +noop +noop +addx 2 +noop +noop +noop +addx 8 +noop +addx -1 +addx 2 +addx 1 +noop +addx 17 +addx -9 +addx 1 +addx 1 +addx -3 +addx 11 +noop +noop +addx 1 +noop +addx 1 +noop +noop +addx -13 +addx -19 +addx 1 +addx 3 +addx 26 +addx -30 +addx 12 +addx -1 +addx 3 +addx 1 +noop +noop +noop +addx -9 +addx 18 +addx 1 +addx 2 +noop +noop +addx 9 +noop +noop +noop +addx -1 +addx 2 +addx -37 +addx 1 +addx 3 +noop +addx 15 +addx -21 +addx 22 +addx -6 +addx 1 +noop +addx 2 +addx 1 +noop +addx -10 +noop +noop +addx 20 +addx 1 +addx 2 +addx 2 +addx -6 +addx -11 +noop +noop +noop +The interesting signal strengths can be determined as follows: + +During the 20th cycle, register X has the value 21, so the signal strength is 20 * 21 = 420. (The 20th cycle occurs in the middle of the second addx -1, so the value of register X is the starting value, 1, plus all of the other addx values up to that point: 1 + 15 - 11 + 6 - 3 + 5 - 1 - 8 + 13 + 4 = 21.) +During the 60th cycle, register X has the value 19, so the signal strength is 60 * 19 = 1140. +During the 100th cycle, register X has the value 18, so the signal strength is 100 * 18 = 1800. +During the 140th cycle, register X has the value 21, so the signal strength is 140 * 21 = 2940. +During the 180th cycle, register X has the value 16, so the signal strength is 180 * 16 = 2880. +During the 220th cycle, register X has the value 18, so the signal strength is 220 * 18 = 3960. +The sum of these signal strengths is 13140. + +Find the signal strength during the 20th, 60th, 100th, 140th, 180th, and 220th cycles. What is the sum of these six signal strengths? + +Your puzzle answer was 11720. + +--- Part Two --- +It seems like the X register controls the horizontal position of a sprite. Specifically, the sprite is 3 pixels wide, and the X register sets the horizontal position of the middle of that sprite. (In this system, there is no such thing as "vertical position": if the sprite's horizontal position puts its pixels where the CRT is currently drawing, then those pixels will be drawn.) + +You count the pixels on the CRT: 40 wide and 6 high. This CRT screen draws the top row of pixels left-to-right, then the row below that, and so on. The left-most pixel in each row is in position 0, and the right-most pixel in each row is in position 39. + +Like the CPU, the CRT is tied closely to the clock circuit: the CRT draws a single pixel during each cycle. Representing each pixel of the screen as a #, here are the cycles during which the first and last pixel in each row are drawn: + +Cycle 1 -> ######################################## <- Cycle 40 +Cycle 41 -> ######################################## <- Cycle 80 +Cycle 81 -> ######################################## <- Cycle 120 +Cycle 121 -> ######################################## <- Cycle 160 +Cycle 161 -> ######################################## <- Cycle 200 +Cycle 201 -> ######################################## <- Cycle 240 +So, by carefully timing the CPU instructions and the CRT drawing operations, you should be able to determine whether the sprite is visible the instant each pixel is drawn. If the sprite is positioned such that one of its three pixels is the pixel currently being drawn, the screen produces a lit pixel (#); otherwise, the screen leaves the pixel dark (.). + +The first few pixels from the larger example above are drawn as follows: + +Sprite position: ###..................................... + +Start cycle 1: begin executing addx 15 +During cycle 1: CRT draws pixel in position 0 +Current CRT row: # + +During cycle 2: CRT draws pixel in position 1 +Current CRT row: ## +End of cycle 2: finish executing addx 15 (Register X is now 16) +Sprite position: ...............###...................... + +Start cycle 3: begin executing addx -11 +During cycle 3: CRT draws pixel in position 2 +Current CRT row: ##. + +During cycle 4: CRT draws pixel in position 3 +Current CRT row: ##.. +End of cycle 4: finish executing addx -11 (Register X is now 5) +Sprite position: ....###................................. + +Start cycle 5: begin executing addx 6 +During cycle 5: CRT draws pixel in position 4 +Current CRT row: ##..# + +During cycle 6: CRT draws pixel in position 5 +Current CRT row: ##..## +End of cycle 6: finish executing addx 6 (Register X is now 11) +Sprite position: ..........###........................... + +Start cycle 7: begin executing addx -3 +During cycle 7: CRT draws pixel in position 6 +Current CRT row: ##..##. + +During cycle 8: CRT draws pixel in position 7 +Current CRT row: ##..##.. +End of cycle 8: finish executing addx -3 (Register X is now 8) +Sprite position: .......###.............................. + +Start cycle 9: begin executing addx 5 +During cycle 9: CRT draws pixel in position 8 +Current CRT row: ##..##..# + +During cycle 10: CRT draws pixel in position 9 +Current CRT row: ##..##..## +End of cycle 10: finish executing addx 5 (Register X is now 13) +Sprite position: ............###......................... + +Start cycle 11: begin executing addx -1 +During cycle 11: CRT draws pixel in position 10 +Current CRT row: ##..##..##. + +During cycle 12: CRT draws pixel in position 11 +Current CRT row: ##..##..##.. +End of cycle 12: finish executing addx -1 (Register X is now 12) +Sprite position: ...........###.......................... + +Start cycle 13: begin executing addx -8 +During cycle 13: CRT draws pixel in position 12 +Current CRT row: ##..##..##..# + +During cycle 14: CRT draws pixel in position 13 +Current CRT row: ##..##..##..## +End of cycle 14: finish executing addx -8 (Register X is now 4) +Sprite position: ...###.................................. + +Start cycle 15: begin executing addx 13 +During cycle 15: CRT draws pixel in position 14 +Current CRT row: ##..##..##..##. + +During cycle 16: CRT draws pixel in position 15 +Current CRT row: ##..##..##..##.. +End of cycle 16: finish executing addx 13 (Register X is now 17) +Sprite position: ................###..................... + +Start cycle 17: begin executing addx 4 +During cycle 17: CRT draws pixel in position 16 +Current CRT row: ##..##..##..##..# + +During cycle 18: CRT draws pixel in position 17 +Current CRT row: ##..##..##..##..## +End of cycle 18: finish executing addx 4 (Register X is now 21) +Sprite position: ....................###................. + +Start cycle 19: begin executing noop +During cycle 19: CRT draws pixel in position 18 +Current CRT row: ##..##..##..##..##. +End of cycle 19: finish executing noop + +Start cycle 20: begin executing addx -1 +During cycle 20: CRT draws pixel in position 19 +Current CRT row: ##..##..##..##..##.. + +During cycle 21: CRT draws pixel in position 20 +Current CRT row: ##..##..##..##..##..# +End of cycle 21: finish executing addx -1 (Register X is now 20) +Sprite position: ...................###.................. +Allowing the program to run to completion causes the CRT to produce the following image: + +##..##..##..##..##..##..##..##..##..##.. +###...###...###...###...###...###...###. +####....####....####....####....####.... +#####.....#####.....#####.....#####..... +######......######......######......#### +#######.......#######.......#######..... +Render the image given by your program. What eight capital letters appear on your CRT? + +Your puzzle answer was ERCREPCJ. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day11/day11.test/UnitTestProblem.cs b/day11/day11.test/UnitTestProblem.cs new file mode 100644 index 0000000..20e66da --- /dev/null +++ b/day11/day11.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day11.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("10605"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("2713310158"); + } +} \ No newline at end of file diff --git a/day11/day11.test/Usings.cs b/day11/day11.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day11/day11.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day11/day11.test/day11.test.csproj b/day11/day11.test/day11.test.csproj new file mode 100644 index 0000000..56ebaa4 --- /dev/null +++ b/day11/day11.test/day11.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day11/day11.test/testdata.txt b/day11/day11.test/testdata.txt new file mode 100644 index 0000000..5bd32e5 --- /dev/null +++ b/day11/day11.test/testdata.txt @@ -0,0 +1,27 @@ +Monkey 0: + Starting items: 79, 98 + Operation: new = old * 19 + Test: divisible by 23 + If true: throw to monkey 2 + If false: throw to monkey 3 + +Monkey 1: + Starting items: 54, 65, 75, 74 + Operation: new = old + 6 + Test: divisible by 19 + If true: throw to monkey 2 + If false: throw to monkey 0 + +Monkey 2: + Starting items: 79, 60, 97 + Operation: new = old * old + Test: divisible by 13 + If true: throw to monkey 1 + If false: throw to monkey 3 + +Monkey 3: + Starting items: 74 + Operation: new = old + 3 + Test: divisible by 17 + If true: throw to monkey 0 + If false: throw to monkey 1 \ No newline at end of file diff --git a/day11/day11/Globals.cs b/day11/day11/Globals.cs new file mode 100644 index 0000000..886a89a --- /dev/null +++ b/day11/day11/Globals.cs @@ -0,0 +1,6 @@ +namespace day11; + +public class Globals +{ + public long old; +} diff --git a/day11/day11/MonkeyV1.cs b/day11/day11/MonkeyV1.cs new file mode 100644 index 0000000..b73e47b --- /dev/null +++ b/day11/day11/MonkeyV1.cs @@ -0,0 +1,53 @@ +namespace day11; + +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; + + +public class MonkeyV1 +{ + public List Items { get; set; } = new(); + + public string NewFormula { get; set; } + + public long TestDivisor { get; set; } + + public int TeskMonkeyTrue { get; set; } + public int TeskMonkeyFalse { get; set; } + public long Inspections { get; set; } + + private Script localScript; + + public void DoTurn(List allMonkeys, long allDivisors) + { + foreach (var item in Items) + { + var globs = new Globals + { + old = item + }; + if (localScript == null) + { + localScript = CSharpScript.Create(NewFormula, globalsType: typeof(Globals)); + localScript.Compile(); + } + + var newWorry = localScript.RunAsync(globs).Result.ReturnValue; + // System.Console.WriteLine($"newWorry: {newWorry}"); + // divide by 3 + newWorry = (int)Math.Ceiling((double)(newWorry / 3)); + // System.Console.WriteLine($"newWorry/3: {newWorry}"); + + if (newWorry % TestDivisor == 0) + { + allMonkeys[TeskMonkeyTrue].Items.Add(newWorry); + } + else + { + allMonkeys[TeskMonkeyFalse].Items.Add(newWorry); + } + } + Inspections += Items.Count; + Items.Clear(); + } +} diff --git a/day11/day11/MonkeyV2.cs b/day11/day11/MonkeyV2.cs new file mode 100644 index 0000000..a422ce4 --- /dev/null +++ b/day11/day11/MonkeyV2.cs @@ -0,0 +1,53 @@ +namespace day11; + +using Microsoft.CodeAnalysis.CSharp.Scripting; +using Microsoft.CodeAnalysis.Scripting; + + +public class MonkeyV2 +{ + public List Items { get; set; } = new(); + + public string NewFormula { get; set; } + + public long TestDivisor { get; set; } + + public int TeskMonkeyTrue { get; set; } + public int TeskMonkeyFalse { get; set; } + public long Inspections { get; set; } + + private Script localScript; + + public void DoTurn(List allMonkeys, long allDivisors) + { + foreach (var item in Items) + { + var globs = new Globals + { + old = item + }; + if (localScript == null) + { + localScript = CSharpScript.Create(NewFormula, globalsType: typeof(Globals)); + localScript.Compile(); + } + + var newWorry = localScript.RunAsync(globs).Result.ReturnValue; + // System.Console.WriteLine($"newWorry: {newWorry}"); + + // optimize large numbers on PROBLEM 2 + newWorry = newWorry % allDivisors; + + if (newWorry % TestDivisor == 0) + { + allMonkeys[TeskMonkeyTrue].Items.Add(newWorry); + } + else + { + allMonkeys[TeskMonkeyFalse].Items.Add(newWorry); + } + } + Inspections += Items.Count; + Items.Clear(); + } +} diff --git a/day11/day11/Problem.cs b/day11/day11/Problem.cs new file mode 100644 index 0000000..47e082d --- /dev/null +++ b/day11/day11/Problem.cs @@ -0,0 +1,114 @@ +namespace day11; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + List allMonkeys = new List(); + + //capture monkeys + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i++]; + //monkey index + var idx = int.Parse(line.Substring(0, line.Length - 1).Split(" ")[1]); + var monkey = new MonkeyV1(); + allMonkeys.Add(monkey); + //items + line = lines[i++]; + monkey.Items.AddRange(line.Split(":")[1].Split(",").Select(x => long.Parse(x))); + //operation + line = lines[i++]; + monkey.NewFormula = line.Split(":")[1].Split("=")[1].Trim(); + //test divisor + line = lines[i++]; + monkey.TestDivisor = int.Parse(line.Substring(" Test: divisible by ".Length)); + //test monkey true + line = lines[i++]; + monkey.TeskMonkeyTrue = int.Parse(line.Substring(" If true: throw to monkey ".Length)); + //test monkey false + line = lines[i++]; + monkey.TeskMonkeyFalse = int.Parse(line.Substring(" If false: throw to monkey".Length)); + } + + long allDivisors = 1; + foreach (var monkey in allMonkeys) + { + allDivisors *= monkey.TestDivisor; + } + var nrRound = 20; + // var nrRound = 10000; + for (int i = 0; i < nrRound; i++) + { + // System.Console.WriteLine($"ROUND: {i + 1}"); + foreach (var monkey in allMonkeys) + { + monkey.DoTurn(allMonkeys, allDivisors); + } + } + + var prods = allMonkeys.OrderByDescending(x => x.Inspections).Take(2).ToArray(); + var monkeyBusiness = prods[0].Inspections * prods[1].Inspections; + // System.Console.WriteLine($"MonkeyBusiness: {monkeyBusiness}"); + + Result1 = monkeyBusiness.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + List allMonkeys = new List(); + + //capture monkeys + for (int i = 0; i < lines.Length; i++) + { + var line = lines[i++]; + //monkey index + var idx = int.Parse(line.Substring(0, line.Length - 1).Split(" ")[1]); + var monkey = new MonkeyV2(); + allMonkeys.Add(monkey); + //items + line = lines[i++]; + monkey.Items.AddRange(line.Split(":")[1].Split(",").Select(x => long.Parse(x))); + //operation + line = lines[i++]; + monkey.NewFormula = line.Split(":")[1].Split("=")[1].Trim(); + //test divisor + line = lines[i++]; + monkey.TestDivisor = int.Parse(line.Substring(" Test: divisible by ".Length)); + //test monkey true + line = lines[i++]; + monkey.TeskMonkeyTrue = int.Parse(line.Substring(" If true: throw to monkey ".Length)); + //test monkey false + line = lines[i++]; + monkey.TeskMonkeyFalse = int.Parse(line.Substring(" If false: throw to monkey".Length)); + } + + long allDivisors = 1; + foreach (var monkey in allMonkeys) + { + allDivisors *= monkey.TestDivisor; + } + //var nrRound = 20; + var nrRound = 10000; + for (int i = 0; i < nrRound; i++) + { + // System.Console.WriteLine($"ROUND: {i + 1}"); + foreach (var monkey in allMonkeys) + { + monkey.DoTurn(allMonkeys, allDivisors); + } + } + + var prods = allMonkeys.OrderByDescending(x => x.Inspections).Take(2).ToArray(); + var monkeyBusiness = prods[0].Inspections * prods[1].Inspections; + // System.Console.WriteLine($"MonkeyBusiness: {monkeyBusiness}"); + + Result2 = monkeyBusiness.ToString(); + } +} diff --git a/day11/day11/Program.cs b/day11/day11/Program.cs new file mode 100644 index 0000000..a6eb085 --- /dev/null +++ b/day11/day11/Program.cs @@ -0,0 +1,18 @@ +namespace day11; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + //50172 + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + //11614682178 + } +} \ No newline at end of file diff --git a/day11/day11/day11.csproj b/day11/day11/day11.csproj new file mode 100644 index 0000000..b634e7e --- /dev/null +++ b/day11/day11/day11.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/day11/day11/input.txt b/day11/day11/input.txt new file mode 100644 index 0000000..ec27405 --- /dev/null +++ b/day11/day11/input.txt @@ -0,0 +1,55 @@ +Monkey 0: + Starting items: 54, 61, 97, 63, 74 + Operation: new = old * 7 + Test: divisible by 17 + If true: throw to monkey 5 + If false: throw to monkey 3 + +Monkey 1: + Starting items: 61, 70, 97, 64, 99, 83, 52, 87 + Operation: new = old + 8 + Test: divisible by 2 + If true: throw to monkey 7 + If false: throw to monkey 6 + +Monkey 2: + Starting items: 60, 67, 80, 65 + Operation: new = old * 13 + Test: divisible by 5 + If true: throw to monkey 1 + If false: throw to monkey 6 + +Monkey 3: + Starting items: 61, 70, 76, 69, 82, 56 + Operation: new = old + 7 + Test: divisible by 3 + If true: throw to monkey 5 + If false: throw to monkey 2 + +Monkey 4: + Starting items: 79, 98 + Operation: new = old + 2 + Test: divisible by 7 + If true: throw to monkey 0 + If false: throw to monkey 3 + +Monkey 5: + Starting items: 72, 79, 55 + Operation: new = old + 1 + Test: divisible by 13 + If true: throw to monkey 2 + If false: throw to monkey 1 + +Monkey 6: + Starting items: 63 + Operation: new = old + 4 + Test: divisible by 19 + If true: throw to monkey 7 + If false: throw to monkey 4 + +Monkey 7: + Starting items: 72, 51, 93, 63, 80, 86, 81 + Operation: new = old * old + Test: divisible by 11 + If true: throw to monkey 0 + If false: throw to monkey 4 \ No newline at end of file diff --git a/day11/problem.md b/day11/problem.md new file mode 100644 index 0000000..3264d80 --- /dev/null +++ b/day11/problem.md @@ -0,0 +1,307 @@ +--- Day 11: Monkey in the Middle --- +As you finally start making your way upriver, you realize your pack is much lighter than you remember. Just then, one of the items from your pack goes flying overhead. Monkeys are playing Keep Away with your missing things! + +To get your stuff back, you need to be able to predict where the monkeys will throw your items. After some careful observation, you realize the monkeys operate based on how worried you are about each item. + +You take some notes (your puzzle input) on the items each monkey currently has, how worried you are about those items, and how the monkey makes decisions based on your worry level. For example: + +Monkey 0: + Starting items: 79, 98 + Operation: new = old * 19 + Test: divisible by 23 + If true: throw to monkey 2 + If false: throw to monkey 3 + +Monkey 1: + Starting items: 54, 65, 75, 74 + Operation: new = old + 6 + Test: divisible by 19 + If true: throw to monkey 2 + If false: throw to monkey 0 + +Monkey 2: + Starting items: 79, 60, 97 + Operation: new = old * old + Test: divisible by 13 + If true: throw to monkey 1 + If false: throw to monkey 3 + +Monkey 3: + Starting items: 74 + Operation: new = old + 3 + Test: divisible by 17 + If true: throw to monkey 0 + If false: throw to monkey 1 +Each monkey has several attributes: + +Starting items lists your worry level for each item the monkey is currently holding in the order they will be inspected. +Operation shows how your worry level changes as that monkey inspects an item. (An operation like new = old * 5 means that your worry level after the monkey inspected the item is five times whatever your worry level was before inspection.) +Test shows how the monkey uses your worry level to decide where to throw an item next. +If true shows what happens with an item if the Test was true. +If false shows what happens with an item if the Test was false. +After each monkey inspects an item but before it tests your worry level, your relief that the monkey's inspection didn't damage the item causes your worry level to be divided by three and rounded down to the nearest integer. + +The monkeys take turns inspecting and throwing items. On a single monkey's turn, it inspects and throws all of the items it is holding one at a time and in the order listed. Monkey 0 goes first, then monkey 1, and so on until each monkey has had one turn. The process of each monkey taking a single turn is called a round. + +When a monkey throws an item to another monkey, the item goes on the end of the recipient monkey's list. A monkey that starts a round with no items could end up inspecting and throwing many items by the time its turn comes around. If a monkey is holding no items at the start of its turn, its turn ends. + +In the above example, the first round proceeds as follows: + +Monkey 0: + Monkey inspects an item with a worry level of 79. + Worry level is multiplied by 19 to 1501. + Monkey gets bored with item. Worry level is divided by 3 to 500. + Current worry level is not divisible by 23. + Item with worry level 500 is thrown to monkey 3. + Monkey inspects an item with a worry level of 98. + Worry level is multiplied by 19 to 1862. + Monkey gets bored with item. Worry level is divided by 3 to 620. + Current worry level is not divisible by 23. + Item with worry level 620 is thrown to monkey 3. +Monkey 1: + Monkey inspects an item with a worry level of 54. + Worry level increases by 6 to 60. + Monkey gets bored with item. Worry level is divided by 3 to 20. + Current worry level is not divisible by 19. + Item with worry level 20 is thrown to monkey 0. + Monkey inspects an item with a worry level of 65. + Worry level increases by 6 to 71. + Monkey gets bored with item. Worry level is divided by 3 to 23. + Current worry level is not divisible by 19. + Item with worry level 23 is thrown to monkey 0. + Monkey inspects an item with a worry level of 75. + Worry level increases by 6 to 81. + Monkey gets bored with item. Worry level is divided by 3 to 27. + Current worry level is not divisible by 19. + Item with worry level 27 is thrown to monkey 0. + Monkey inspects an item with a worry level of 74. + Worry level increases by 6 to 80. + Monkey gets bored with item. Worry level is divided by 3 to 26. + Current worry level is not divisible by 19. + Item with worry level 26 is thrown to monkey 0. +Monkey 2: + Monkey inspects an item with a worry level of 79. + Worry level is multiplied by itself to 6241. + Monkey gets bored with item. Worry level is divided by 3 to 2080. + Current worry level is divisible by 13. + Item with worry level 2080 is thrown to monkey 1. + Monkey inspects an item with a worry level of 60. + Worry level is multiplied by itself to 3600. + Monkey gets bored with item. Worry level is divided by 3 to 1200. + Current worry level is not divisible by 13. + Item with worry level 1200 is thrown to monkey 3. + Monkey inspects an item with a worry level of 97. + Worry level is multiplied by itself to 9409. + Monkey gets bored with item. Worry level is divided by 3 to 3136. + Current worry level is not divisible by 13. + Item with worry level 3136 is thrown to monkey 3. +Monkey 3: + Monkey inspects an item with a worry level of 74. + Worry level increases by 3 to 77. + Monkey gets bored with item. Worry level is divided by 3 to 25. + Current worry level is not divisible by 17. + Item with worry level 25 is thrown to monkey 1. + Monkey inspects an item with a worry level of 500. + Worry level increases by 3 to 503. + Monkey gets bored with item. Worry level is divided by 3 to 167. + Current worry level is not divisible by 17. + Item with worry level 167 is thrown to monkey 1. + Monkey inspects an item with a worry level of 620. + Worry level increases by 3 to 623. + Monkey gets bored with item. Worry level is divided by 3 to 207. + Current worry level is not divisible by 17. + Item with worry level 207 is thrown to monkey 1. + Monkey inspects an item with a worry level of 1200. + Worry level increases by 3 to 1203. + Monkey gets bored with item. Worry level is divided by 3 to 401. + Current worry level is not divisible by 17. + Item with worry level 401 is thrown to monkey 1. + Monkey inspects an item with a worry level of 3136. + Worry level increases by 3 to 3139. + Monkey gets bored with item. Worry level is divided by 3 to 1046. + Current worry level is not divisible by 17. + Item with worry level 1046 is thrown to monkey 1. +After round 1, the monkeys are holding items with these worry levels: + +Monkey 0: 20, 23, 27, 26 +Monkey 1: 2080, 25, 167, 207, 401, 1046 +Monkey 2: +Monkey 3: +Monkeys 2 and 3 aren't holding any items at the end of the round; they both inspected items during the round and threw them all before the round ended. + +This process continues for a few more rounds: + +After round 2, the monkeys are holding items with these worry levels: +Monkey 0: 695, 10, 71, 135, 350 +Monkey 1: 43, 49, 58, 55, 362 +Monkey 2: +Monkey 3: + +After round 3, the monkeys are holding items with these worry levels: +Monkey 0: 16, 18, 21, 20, 122 +Monkey 1: 1468, 22, 150, 286, 739 +Monkey 2: +Monkey 3: + +After round 4, the monkeys are holding items with these worry levels: +Monkey 0: 491, 9, 52, 97, 248, 34 +Monkey 1: 39, 45, 43, 258 +Monkey 2: +Monkey 3: + +After round 5, the monkeys are holding items with these worry levels: +Monkey 0: 15, 17, 16, 88, 1037 +Monkey 1: 20, 110, 205, 524, 72 +Monkey 2: +Monkey 3: + +After round 6, the monkeys are holding items with these worry levels: +Monkey 0: 8, 70, 176, 26, 34 +Monkey 1: 481, 32, 36, 186, 2190 +Monkey 2: +Monkey 3: + +After round 7, the monkeys are holding items with these worry levels: +Monkey 0: 162, 12, 14, 64, 732, 17 +Monkey 1: 148, 372, 55, 72 +Monkey 2: +Monkey 3: + +After round 8, the monkeys are holding items with these worry levels: +Monkey 0: 51, 126, 20, 26, 136 +Monkey 1: 343, 26, 30, 1546, 36 +Monkey 2: +Monkey 3: + +After round 9, the monkeys are holding items with these worry levels: +Monkey 0: 116, 10, 12, 517, 14 +Monkey 1: 108, 267, 43, 55, 288 +Monkey 2: +Monkey 3: + +After round 10, the monkeys are holding items with these worry levels: +Monkey 0: 91, 16, 20, 98 +Monkey 1: 481, 245, 22, 26, 1092, 30 +Monkey 2: +Monkey 3: + +... + +After round 15, the monkeys are holding items with these worry levels: +Monkey 0: 83, 44, 8, 184, 9, 20, 26, 102 +Monkey 1: 110, 36 +Monkey 2: +Monkey 3: + +... + +After round 20, the monkeys are holding items with these worry levels: +Monkey 0: 10, 12, 14, 26, 34 +Monkey 1: 245, 93, 53, 199, 115 +Monkey 2: +Monkey 3: +Chasing all of the monkeys at once is impossible; you're going to have to focus on the two most active monkeys if you want any hope of getting your stuff back. Count the total number of times each monkey inspects items over 20 rounds: + +Monkey 0 inspected items 101 times. +Monkey 1 inspected items 95 times. +Monkey 2 inspected items 7 times. +Monkey 3 inspected items 105 times. +In this example, the two most active monkeys inspected items 101 and 105 times. The level of monkey business in this situation can be found by multiplying these together: 10605. + +Figure out which monkeys to chase by counting how many items they inspect over 20 rounds. What is the level of monkey business after 20 rounds of stuff-slinging simian shenanigans? + +Your puzzle answer was 50172. + +--- Part Two --- +You're worried you might not ever get your items back. So worried, in fact, that your relief that a monkey's inspection didn't damage an item no longer causes your worry level to be divided by three. + +Unfortunately, that relief was all that was keeping your worry levels from reaching ridiculous levels. You'll need to find another way to keep your worry levels manageable. + +At this rate, you might be putting up with these monkeys for a very long time - possibly 10000 rounds! + +With these new rules, you can still figure out the monkey business after 10000 rounds. Using the same example above: + +== After round 1 == +Monkey 0 inspected items 2 times. +Monkey 1 inspected items 4 times. +Monkey 2 inspected items 3 times. +Monkey 3 inspected items 6 times. + +== After round 20 == +Monkey 0 inspected items 99 times. +Monkey 1 inspected items 97 times. +Monkey 2 inspected items 8 times. +Monkey 3 inspected items 103 times. + +== After round 1000 == +Monkey 0 inspected items 5204 times. +Monkey 1 inspected items 4792 times. +Monkey 2 inspected items 199 times. +Monkey 3 inspected items 5192 times. + +== After round 2000 == +Monkey 0 inspected items 10419 times. +Monkey 1 inspected items 9577 times. +Monkey 2 inspected items 392 times. +Monkey 3 inspected items 10391 times. + +== After round 3000 == +Monkey 0 inspected items 15638 times. +Monkey 1 inspected items 14358 times. +Monkey 2 inspected items 587 times. +Monkey 3 inspected items 15593 times. + +== After round 4000 == +Monkey 0 inspected items 20858 times. +Monkey 1 inspected items 19138 times. +Monkey 2 inspected items 780 times. +Monkey 3 inspected items 20797 times. + +== After round 5000 == +Monkey 0 inspected items 26075 times. +Monkey 1 inspected items 23921 times. +Monkey 2 inspected items 974 times. +Monkey 3 inspected items 26000 times. + +== After round 6000 == +Monkey 0 inspected items 31294 times. +Monkey 1 inspected items 28702 times. +Monkey 2 inspected items 1165 times. +Monkey 3 inspected items 31204 times. + +== After round 7000 == +Monkey 0 inspected items 36508 times. +Monkey 1 inspected items 33488 times. +Monkey 2 inspected items 1360 times. +Monkey 3 inspected items 36400 times. + +== After round 8000 == +Monkey 0 inspected items 41728 times. +Monkey 1 inspected items 38268 times. +Monkey 2 inspected items 1553 times. +Monkey 3 inspected items 41606 times. + +== After round 9000 == +Monkey 0 inspected items 46945 times. +Monkey 1 inspected items 43051 times. +Monkey 2 inspected items 1746 times. +Monkey 3 inspected items 46807 times. + +== After round 10000 == +Monkey 0 inspected items 52166 times. +Monkey 1 inspected items 47830 times. +Monkey 2 inspected items 1938 times. +Monkey 3 inspected items 52013 times. +After 10000 rounds, the two most active monkeys inspected items 52166 and 52013 times. Multiplying these together, the level of monkey business in this situation is now 2713310158. + +Worry levels are no longer divided by three after each item is inspected; you'll need to find another way to keep your worry levels manageable. Starting again from the initial state in your puzzle input, what is the level of monkey business after 10000 rounds? + +Your puzzle answer was 11614682178. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day12/day12.test/UnitTestProblem.cs b/day12/day12.test/UnitTestProblem.cs new file mode 100644 index 0000000..8459a49 --- /dev/null +++ b/day12/day12.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day12.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("31"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("29"); + } +} \ No newline at end of file diff --git a/day12/day12.test/Usings.cs b/day12/day12.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day12/day12.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day12/day12.test/day12.test.csproj b/day12/day12.test/day12.test.csproj new file mode 100644 index 0000000..1eacc02 --- /dev/null +++ b/day12/day12.test/day12.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day12/day12.test/testdata.txt b/day12/day12.test/testdata.txt new file mode 100644 index 0000000..433e0d2 --- /dev/null +++ b/day12/day12.test/testdata.txt @@ -0,0 +1,5 @@ +Sabqponm +abcryxxl +accszExk +acctuvwj +abdefghi \ No newline at end of file diff --git a/day12/day12/Node.cs b/day12/day12/Node.cs new file mode 100644 index 0000000..fcbbecc --- /dev/null +++ b/day12/day12/Node.cs @@ -0,0 +1,99 @@ +namespace day12; + +using FastGraph; +using FastGraph.Algorithms; + +public class Node +{ + private Node() { } + + public static AdjacencyGraph> + graph = new FastGraph.AdjacencyGraph>(); + + public static void InitGraph() + { + graph = new FastGraph.AdjacencyGraph>(); + AllNodes.Clear(); + } + + public static List AllNodes = new(); + public static Node Create(int x, int y, string value) + { + var node = new Node + { + X = x, + Y = y, + Value = value + }; + AllNodes.Add(node); + + //add vertex to graph + graph.AddVertex(node); + + return node; + } + public int X { get; set; } + public int Y { get; set; } + public string Value { get; set; } + public List Vertices { get; set; } = new List(); + + private bool IsFilled = false; + + public void AddVertices(string[] lines) + { + if (IsFilled) + return; + // System.Console.WriteLine($"node: {X} - {Y}"); + TryAddVertice(lines, Value, X - 1, Y); + TryAddVertice(lines, Value, X + 1, Y); + TryAddVertice(lines, Value, X, Y - 1); + TryAddVertice(lines, Value, X, Y + 1); + IsFilled = true; + foreach (var vertice in Vertices) + { + vertice.AddVertices(lines); + } + } + + private void TryAddVertice(string[] lines, string currentValue, int chkX, int chkY) + { + if (chkX < 0 || chkY < 0 || chkY > lines.Length - 1 || chkX > lines[0].Length - 1) + return; + + if ( + (lines[chkY][chkX] >= 'a' && //Value[0] - 1 && + lines[chkY][chkX] <= (Value[0] + 1)) || + (lines[chkY][chkX] == 'E' && 'z' >= Value[0] - 1 && 'z' <= Value[0] + 1)) + { + var existNode = AllNodes.FirstOrDefault(n => n.X == chkX && n.Y == chkY); + if (existNode == null) + { + //create node + var chkNode = Node.Create(chkX, chkY, lines[chkY][chkX].ToString()); + Vertices.Add(chkNode); + // System.Console.WriteLine($"add vertice {chkX} - {chkY} : {lines[chkY][chkX].ToString()}"); + // add edge to graph + var edge1 = new TaggedEdge(this, chkNode, "create hello"); + graph.AddEdge(edge1); + } + else + { + //reuse node - link + if (!Vertices.Contains(existNode)) + { + Vertices.Add(existNode); + //link + // System.Console.WriteLine($"link vertice {chkX} - {chkY} : {lines[chkY][chkX].ToString()}"); + // add edge to graph + var edge1 = new TaggedEdge(this, existNode, "link hello"); + graph.AddEdge(edge1); + } + } + } + } + + public override string ToString() + { + return $"N:{X}-{Y}:{Value}"; + } +} diff --git a/day12/day12/Problem.cs b/day12/day12/Problem.cs new file mode 100644 index 0000000..f714773 --- /dev/null +++ b/day12/day12/Problem.cs @@ -0,0 +1,113 @@ +namespace day12; + +using FastGraph; +using FastGraph.Algorithms; + +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var nrLines = lines.Length; + var nrColumns = lines[0].Length; + + var aStarts = new List<(int X, int Y)>(); + for (int i = 0; i < nrLines; i++) + { + var line = lines[i]; + var lineIdx = 0; + while ((lineIdx = line.IndexOfAny("S".ToArray(), lineIdx)) >= 0) + { + aStarts.Add((lineIdx++, i)); + } + } + + var endY = Array.IndexOf(lines, lines.First(x => x.Contains("E"))); + var endX = lines[endY].IndexOf('E'); + // System.Console.WriteLine($"E: {endX} - {endY}"); + + var startY = aStarts.First().Y; + var startX = aStarts.First().X; + // System.Console.WriteLine($"S: {startX} - {startY}"); + + Node.InitGraph(); + var root = Node.Create(startX, startY, "a"); + root.AddVertices(lines); + + var currentPathCount = -1; + var endNode = Node.AllNodes.FirstOrDefault(n => n.X == endX && n.Y == endY); + if (endNode != null) + { + var tryGetPaths = Node.graph.ShortestPathsDijkstra(t => 1, root); + if (tryGetPaths(endNode, out IEnumerable> path)) + { + currentPathCount = path.Count(); + } + } + // else + // { + // System.Console.WriteLine("end node not reacheable."); + // } + + Result1 = currentPathCount.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + var nrLines = lines.Length; + var nrColumns = lines[0].Length; + + var aStarts = new List<(int X, int Y)>(); + for (int i = 0; i < nrLines; i++) + { + var line = lines[i]; + var lineIdx = 0; + while ((lineIdx = line.IndexOfAny("aS".ToArray(), lineIdx)) >= 0) + { + aStarts.Add((i, lineIdx++)); + } + } + + var endY = Array.IndexOf(lines, lines.First(x => x.Contains("E"))); + var endX = lines[endY].IndexOf('E'); + // System.Console.WriteLine($"E: {endX} - {endY}"); + + var minPathCount = int.MaxValue; + foreach (var start in aStarts) + { + var startY = start.X; + var startX = start.Y; + // System.Console.WriteLine($"S: {startX} - {startY}"); + + Node.InitGraph(); + var root = Node.Create(startX, startY, "a"); + root.AddVertices(lines); + + // System.Console.WriteLine($"Graph nodes: {Node.graph.VertexCount}"); + + var endNode = Node.AllNodes.FirstOrDefault(n => n.X == endX && n.Y == endY); + if (endNode != null) + { + var tryGetPaths = Node.graph.ShortestPathsDijkstra(t => 1, root); + if (tryGetPaths(endNode, out IEnumerable> path)) + { + var currentPathCount = path.Count(); + minPathCount = Math.Min(minPathCount, currentPathCount); + } + } + // else + // { + // System.Console.WriteLine("end node not reacheable."); + // } + } + + // System.Console.WriteLine($"minPathCount: {minPathCount}"); + Result2 = minPathCount.ToString(); + } +} diff --git a/day12/day12/Program.cs b/day12/day12/Program.cs new file mode 100644 index 0000000..37f0d3d --- /dev/null +++ b/day12/day12/Program.cs @@ -0,0 +1,18 @@ +namespace day12; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + //456 + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + //454 + } +} \ No newline at end of file diff --git a/day12/day12/day12.csproj b/day12/day12/day12.csproj new file mode 100644 index 0000000..91d660e --- /dev/null +++ b/day12/day12/day12.csproj @@ -0,0 +1,17 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + + diff --git a/day12/day12/input.txt b/day12/day12/input.txt new file mode 100644 index 0000000..bf4f39a --- /dev/null +++ b/day12/day12/input.txt @@ -0,0 +1,41 @@ +abcccccccccccccccccccccccccccccccccccccaaaaaaacccccccaaaaaaaaaaaccccccccccccccccccccaaacaaaaaaaacccccccccccccccccccccccccccccccccccaaaaa +abccccccccccccccccccaaccaacccccccccccccaaaaaaaccccccccaaaaaaaaaaacccccccaaaaccccccccaaaaaaaaaaaaacccccccccccccccccccccccccccccccccaaaaaa +abccccccccccccccccccaaaaaaccccccccccaaaccaaaaaacccccccaaaaaaaaaaccccccccaaaaccccccaaaaaaaaaaaaaaacccccccccccccccccccaaacccccccccccaaaaaa +abcccccccccccccccccccaaaaacccccccccccaaccaacaaaccccccaaaaaaaaaaaccccccccaaaacccccaaaaaaaaacaaaaaaacccccccccccccccccaaaacccccccccccaaacaa +abccccccccccccccccccaaaaaaccccccccaacaaaaaacccccccccaaaaaaaaaaaaacaaaccccaaccccccaaaaaaaaacaacccccccccccccccccaaaccaaaacccccccccccccccaa +abcccccccccccccccccaaaaaaaacccccccaaaaaaaaccccccaaaaaaaacaaaacaaaaaaacccccccccaaccccaaaaaacaaacccccccccccccccaaaakkkaaccccccccccccccccaa +abcccccccccccccccccaaaaaaaaccccccccaaaaaccccaacccaaaaaaaaaaaacaaaaaaccccccccccaacccaaaaaaaaaaaacccccccccccccccakkkkkklcccccccccccccccccc +abaaacccccccccccaaccccaaccccccccccccaaaaaccaaacccaaaaaaaaaaaaaaaaaaaaccccccaaaaaaaacaacccaaaaaaccccccccccccccckkkkkkkllcccccccaaaccccccc +abaaaacccccccaacaaccccaacccccccccccaaacaaaaaaaccccaaaaaaaaaaaaaaaaaaaacccccaaaaaaaaaaaccccaaaaacccccccccccccckkkksssllllccccccaaaaaacccc +abaaaacccccccaaaaacccccccccccaaaccccaacaaaaaaccccaaaaaacaaaaaaaaaaaaaacccccccaaaaccccccccaaaaacccccccccccccckkkksssssllllcccccaaaaaacccc +abaaacccccccccaaaaaaccccccccaaaaccccccccaaaaaaaacaaaaaaaaaaaaacaaacaaacccccccaaaaacccccccaaaaacccccccccccccjkkkrssssssllllccccccaaaccccc +abccccccccccaaaaaaaaccccccccaaaacccccccaaaaaaaaacaacaaaaaaaaaacaaaccccccccccaaacaaccccccccccccccccccccccccjjkkrrsuuussslllllcccccaaccccc +abccaaacccccaaaaacccccccccccaaaaccccccaaaaaaaaaacccccaaaaaaaaaacaaccccccccccaacccacccccccccccccccccccccjjjjjjrrrsuuuussslllllmcccddacccc +abcccaaaccaccacaaaccccccccccccccccccccaaaaaaaccccccccccaaaaaaaaccccccaacccccccccccaaaaacccccccccccccccjjjjjjrrrruuuuuusssllmmmmmddddcccc +abccaaaaaaaacccaaaccccccccccccccccaaacccccaaaccccccccccccaaacccccccccaacccccccccccaaaaacccccccccccccjjjjjrrrrrruuuxuuussqqqqmmmmmdddcccc +abcaaaaaaaacccaaaaaacaaaaaccccccaaaaaaccccaaacccaaccccccccaaccccccaaaaaaaaccaaacccaaaaaaccccccccccccjjjjrrrrrruuuxxxuuuqqqqqqqmmmdddcccc +abaaaaaaaaaccccaaaaacaaaaaccccccaaaaaaaaccccccaaaaaaccccccccccccccaaaaaaaaccaaacaaaaaaaacccccccccccjjjjrrrtttuuuuxxxyvvvvvqqqqmmmdddcccc +abaaaaaaaaaccaaaaaaacaaaaaaccccccaaaaaaaacccccaaaaaaccccccccccccccccaaaaccaaaaaaaaaaaaaacccccccccaaiijqqqrttttuuuxxyyvvvvvvvqqmmmdddcccc +abcaaaaaaaaccaaaaaaaaaaaaaacccccaaaaaaaacccccccaaaacccccaaaaccccccccaaaaacaaaaaaaaccaaccccccccccaaaiiiqqqttttxxxxxxyyyyyyvvvqqmmmdddcccc +abcccaaaaaaacaaaaaaaaaaaaaacccccaaaaaaaaaaaccccaaaaccccaaaaacccccccaaaaaacaaaaaaacccccccccccccccaaaiiiqqqtttxxxxxxxyyyyyyvvqqqmmmdddcccc +SbcccaacccaccccaaacacccaaacccccccccaaaaaaaaacccaccaccccaaaaaaccccccaaccaacccaaaaaccccccccccccccccaaiiiiqqtttxxxxEzzzyyyyvvvqqqmmmddccccc +abccaaaccccccccaaccccccccccccccccccaaaaaaaaccccccccccccaaaaaaccccccccccccccaaacaaaccaacccccccccccccciiiqqqttttxxxyyyyyvvvvqqqmmmdddccccc +abccccccccccccccccccccccccccccccccaaaaaaaccccccccccccccaaaaaacccccccccccccccaacccccaaaaaaaccccccccccciiiqqqttttxxyyyyyvvvrrrnnneeecccccc +abcaaaaccccccccccccccccccccccccccaaaaaaaaccccccccccccccccaacccccccccccccccccccccccccaaaaacccccccccccciiiqqqqttxxyyyyyyyvvrrnnnneeecccccc +abcaaaaacccccccccccccccccccccccccaaaacaaacccaccaaacccccccccccccccccccccccccaaaccccaaaaaaaccccccccccccciiiqqqttwwyywwyyywwrrnnneeeccccccc +abaaaaaacccaccaccccccccccccccccccaaaaccaacccaaaaaaccccccccccccccccaaaccccaaaaaacccaaaaaaaacccccccccccciiiqqqtswwwwwwwwwwwrrnnneeeccccccc +abaaaaaacccaaaaccccccccaaaacccccccaaacccccccaaaaaacccccccccccccccaaaaaaccaaaaaacccaaaaaaaacaaccccccaaciiiqppsswwwwsswwwwwrrrnneeeccccccc +abcaaaaacccaaaaacccccccaaaacccccccccccccccccaaaaaaaccccccccccccccaaaaaaccaaaaaacccccaaaaaaaaaccccccaaaahhpppssswwsssswwwwrrrnneeeacccccc +abcaaaccccaaaaaacccccccaaaaccccccccccccccccaaaaaaaaccccccccccccccaaaaacccaaaaaccccccaacaaaaaaaaccaaaaaahhpppsssssssssrrrrrrnnneeeacccccc +abccccccccaaaaaaccccccccaacccccccccccccccccaaaaaaaaccccaacccccccccaaaaaccaaaaacccccccccaaaaaaaaccaaaaachhpppssssssoosrrrrrrnnneeeaaacccc +abccccccccccaaccccccccccccccccaaaaaccccccaacccaaacccaaaaacccccccccaacaacccccccccccccccccaaaaaaacccaaaaahhhppppssppooooorroonnffeaaaacccc +abaaccccccccccccccccccccccccccaaaaaccccccaacccaaaccccaaaaacccccccccccccccccccccccccccaacaaaaacccccaacaahhhppppppppoooooooooonfffaaaacccc +abaccccccccccccccccccccccccccaaaaaacccaaaaaaaacccccccaaaaaccccccccccccccccccccccccaaaaaaaaaaaccccccccccchhhpppppppgggoooooooffffaacccccc +abaccccccccccccccccccccccccccaaaaaacccaaaaaaaaccccccaaaaaccccccacccaacccccccccccccaaaaaccccaaccccccccccchhhhhhggggggggfffffffffaaacccccc +abaacccccccccccccccccccccccccaaaaaacccccaaaacccccccccaaaacccaacaacaaacccccccccccccaaaaaaacccccccccccccccchhhhgggggggggffffffffccaacccccc +abcccccccaacccccccccccccccccccaaaccccccaaaaaccccccccaaaaccaaaacaaaaacccccccccccccaaaaaaaaccccccccccccccccchhhggggaaaagffffffcccccccccccc +abcccccccaacccccccccccccaacccccccccccccaaaaaaccaaccccaaaaaaaaacaaaaaacccccccaaaacaaaaaaaacccccccccccaacccccccaaaacaaaacccccccccccccccccc +abccccaaaaaaaacccccccaacaaaccccccccccccaaccaacaaaacccaaaaaaaacaaaaaaaaccccccaaaaccacaaaccaaaccccaaaaaacccccccaacccaaaacccccccccccccaaaaa +abccccaaaaaaaacccccccaaaaaccccccccccccccccccccaaaaccccaaaaaaacaaaaaaaaccccccaaaaccccaaaccaaaaaccaaaaaaaacccccccccccaaaccccccccccccccaaaa +abccccccaaaaccccccccccaaaaaaccccccccccccccccccaaaacccaaaaaaaaaaccaaccccccccccaacccccccccaaaaacccaaaaaaaacccccccccccaaaccccccccccccccaaaa +abcccccaaaaaacccccccaaaaaaaacccccccccccccccccccccccaaaaaaaaaaaaaaaacccccccccccccccccccccaaaaaacccaaaaaaaccccccccccccccccccccccccccaaaaaa \ No newline at end of file diff --git a/day12/problem.md b/day12/problem.md new file mode 100644 index 0000000..9673559 --- /dev/null +++ b/day12/problem.md @@ -0,0 +1,63 @@ +--- Day 12: Hill Climbing Algorithm --- +You try contacting the Elves using your handheld device, but the river you're following must be too low to get a decent signal. + +You ask the device for a heightmap of the surrounding area (your puzzle input). The heightmap shows the local area from above broken into a grid; the elevation of each square of the grid is given by a single lowercase letter, where a is the lowest elevation, b is the next-lowest, and so on up to the highest elevation, z. + +Also included on the heightmap are marks for your current position (S) and the location that should get the best signal (E). Your current position (S) has elevation a, and the location that should get the best signal (E) has elevation z. + +You'd like to reach E, but to save energy, you should do it in as few steps as possible. During each step, you can move exactly one square up, down, left, or right. To avoid needing to get out your climbing gear, the elevation of the destination square can be at most one higher than the elevation of your current square; that is, if your current elevation is m, you could step to elevation n, but not to elevation o. (This also means that the elevation of the destination square can be much lower than the elevation of your current square.) + +For example: + +Sabqponm +abcryxxl +accszExk +acctuvwj +abdefghi +Here, you start in the top-left corner; your goal is near the middle. You could start by moving down or right, but eventually you'll need to head toward the e at the bottom. From there, you can spiral around to the goal: + +v..v<<<< +>v.vv<<^ +.>vv>E^^ +..v>>>^^ +..>>>>>^ +In the above diagram, the symbols indicate whether the path exits each square moving up (^), down (v), left (<), or right (>). The location that should get the best signal is still E, and . marks unvisited squares. + +This path reaches the goal in 31 steps, the fewest possible. + +What is the fewest steps required to move from your current position to the location that should get the best signal? + +Your puzzle answer was 456. + +--- Part Two --- +As you walk up the hill, you suspect that the Elves will want to turn this into a hiking trail. The beginning isn't very scenic, though; perhaps you can find a better starting point. + +To maximize exercise while hiking, the trail should start as low as possible: elevation a. The goal is still the square marked E. However, the trail should still be direct, taking the fewest steps to reach its goal. So, you'll need to find the shortest path from any square at elevation a to the square marked E. + +Again consider the example from above: + +Sabqponm +abcryxxl +accszExk +acctuvwj +abdefghi +Now, there are six choices for starting position (five marked a, plus the square marked S that counts as being at elevation a). If you start at the bottom-left square, you can reach the goal most quickly: + +...v<<<< +...vv<<^ +...v>E^^ +.>v>>>^^ +>^>>>>>^ +This path reaches the goal in only 29 steps, the fewest possible. + +What is the fewest steps required to move starting from any square with elevation a to the location that should get the best signal? + +Your puzzle answer was 454. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day13/day13.test/UnitTestProblem.cs b/day13/day13.test/UnitTestProblem.cs new file mode 100644 index 0000000..f549da4 --- /dev/null +++ b/day13/day13.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day13.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("13"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("140"); + } +} \ No newline at end of file diff --git a/day13/day13.test/Usings.cs b/day13/day13.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day13/day13.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day13/day13.test/day13.test.csproj b/day13/day13.test/day13.test.csproj new file mode 100644 index 0000000..b88ae0d --- /dev/null +++ b/day13/day13.test/day13.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day13/day13.test/testdata.txt b/day13/day13.test/testdata.txt new file mode 100644 index 0000000..27c8912 --- /dev/null +++ b/day13/day13.test/testdata.txt @@ -0,0 +1,23 @@ +[1,1,3,1,1] +[1,1,5,1,1] + +[[1],[2,3,4]] +[[1],4] + +[9] +[[8,7,6]] + +[[4,4],4,4] +[[4,4],4,4,4] + +[7,7,7,7] +[7,7,7] + +[] +[3] + +[[[]]] +[[]] + +[1,[2,[3,[4,[5,6,7]]]],8,9] +[1,[2,[3,[4,[5,6,0]]]],8,9] \ No newline at end of file diff --git a/day13/day13/Message.cs b/day13/day13/Message.cs new file mode 100644 index 0000000..dd407b2 --- /dev/null +++ b/day13/day13/Message.cs @@ -0,0 +1,90 @@ +namespace day13; + +using System.Text.Json; + +public class Message +{ + protected Message() { } + public List Values { get; set; } = new List(); + public int Value { get; set; } + public bool IsList { get; set; } + public string StringValue { get; private set; } + + public static Message CreateFromJsonElement(JsonElement jsonEl) + { + var result = new Message(); + if (jsonEl.ValueKind == JsonValueKind.Array) + { + result.IsList = true; + var arr = jsonEl.EnumerateArray().ToArray(); + foreach (var item in arr) + { + result.Values.Add(CreateFromJsonElement(item)); + } + } + else if (jsonEl.ValueKind == JsonValueKind.Number) + { + result.IsList = false; + result.Value = jsonEl.GetInt32(); + } + return result; + } + public static Message Create(string msg) + { + var jsonElement = (JsonElement)JsonSerializer.Deserialize(msg); + + var result = CreateFromJsonElement(jsonElement); + result.StringValue = msg; + return result; + } + + public int Compare(Message other) + { + if (!this.IsList && !other.IsList) + { + //numeric comparison + return this.Value.CompareTo(other.Value); + } + else if (this.IsList && !other.IsList) + { + //first is list + var secList = new Message + { + IsList = true + }; + secList.Values.Add(other); + return this.Compare(secList); + } + else if (!this.IsList && other.IsList) + { + //second is list + var firstList = new Message + { + IsList = true + }; + firstList.Values.Add(this); + return firstList.Compare(other); + } + else if (this.IsList && other.IsList) + { + //both are list + var thisCount = this.Values.Count; + var otherCount = other.Values.Count; + for (int i = 0; i < Math.Min(thisCount, otherCount); i++) + { + var localComp = this.Values[i].Compare(other.Values[i]); + if (localComp != 0) + { + return localComp; + } + } + return thisCount.CompareTo(otherCount); + } + throw new NotSupportedException("situation impossible"); + } + + public override string ToString() + { + return StringValue; + } +} \ No newline at end of file diff --git a/day13/day13/Problem.cs b/day13/day13/Problem.cs new file mode 100644 index 0000000..f6afc2d --- /dev/null +++ b/day13/day13/Problem.cs @@ -0,0 +1,64 @@ +namespace day13; + +/// +/// HINT - https://github.com/jcollard/AdventOfCode2022/tree/main/Day13 +/// +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + var inRightOrder = 0; + var idx = 0; + var idxSum = 0; + for (int i = 0; i < lines.Length; i++) + { + idx++; + var line1 = lines[i++]; + var line2 = lines[i++]; + + Message msg1 = Message.Create(line1); + Message msg2 = Message.Create(line2); + + if (msg1.Compare(msg2) <= 0) + { + inRightOrder++; + idxSum += idx; + } + } + + // System.Console.WriteLine($"inRightOrder: {inRightOrder} sum: {idxSum}"); + Result1 = idxSum.ToString(); + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + // PROBLEM 2 + List lstMessages = new(); + for (int i = 0; i < lines.Length; i++) + { + var line1 = lines[i++]; + lstMessages.Add(Message.Create(line1)); + var line2 = lines[i++]; + lstMessages.Add(Message.Create(line2)); + } + var div1 = Message.Create("[[2]]"); + lstMessages.Add(div1); + var div2 = Message.Create("[[6]]"); + lstMessages.Add(div2); + lstMessages.Sort((a, b) => a.Compare(b)); + + var idxDiv1 = lstMessages.IndexOf(div1) + 1; + var idxDiv2 = lstMessages.IndexOf(div2) + 1; + var decoderKey = idxDiv1 * idxDiv2; + + // System.Console.WriteLine($"decoderKey: {decoderKey}"); + Result2 = decoderKey.ToString(); + } +} diff --git a/day13/day13/Program.cs b/day13/day13/Program.cs new file mode 100644 index 0000000..577d4be --- /dev/null +++ b/day13/day13/Program.cs @@ -0,0 +1,18 @@ +namespace day13; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + //6420 + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + //22000 + } +} diff --git a/day13/day13/day13.csproj b/day13/day13/day13.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day13/day13/day13.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day13/day13/input.txt b/day13/day13/input.txt new file mode 100644 index 0000000..25c5469 --- /dev/null +++ b/day13/day13/input.txt @@ -0,0 +1,449 @@ +[[[[4,7,7],0,4,[6,3,3,7,10],2],2,[[3]]],[]] +[[[[1,4,8],[3,3,1,4]]]] + +[[7,6],[],[[5],0,10,[7,9,[7],0]]] +[[[[6,9,0]],0]] + +[[7,7,[[5,1,4,9,4],8,[8],[1,1,6,2]],[[],3,6,[],[]]],[],[10,2,7],[0,[1,2,4,1,0],[1,[],0],5,[]],[4,[[],[],[]],[]]] +[[3,6],[[9,6,[]],8,[8,8,3,[8,2,3,10],[6,5]],[6,4,[8,5],8]]] + +[[[[4,8,1,3,4],[2,4,10,5,4],[7,7],7],[[9,8,4,7,0]],8,[3,1]],[[],[[9,3],5],[],7,[[],8,8,[6,0,3,10,2],[0,8,7,0]]],[9,[4],7,3]] +[[5],[[[],[],[7,10]],3,6],[[[],4,[8,6,3,1],0,[5,1,0,4]],[],[[9,5]],4]] + +[[6,10,9,[],[[2]]],[9,[10,[3,5,0],[6,5]]],[],[[8,[2,2,3]],6]] +[[],[[],9,[9,2,[6,8,10,3],2],9,3]] + +[[[[3],[]],5],[[],[7,[3,3,3],2,[1],[6,7,9]],[],8,1],[9,[0,0,[5,3,5,1],[2],2],3],[2,[0,4]]] +[[[]],[[[],10,[8,0,5,5],[5,4,8,10,1],[6,8,0,3,5]],2,[9,[5],[9,2],[]],[8,[]]]] + +[[3],[[8],6,5],[]] +[[],[0],[],[3,0],[]] + +[[0,[[9],[],[6,10,9,9,6],[1,1,10,6],[1,2,6]]],[]] +[[[3,[5,3,7,10,5],[9,2,1]],[[3,7,0,6]],[[]],[4,[1]],[8,8,[2,4,8,3]]],[[5,6],[]],[[],5],[]] + +[[3,4,[[1,6,10],[10],[1],[]],8,[[4,10,3]]],[9,8,0,0]] +[[0,[9],[],9,0],[6],[[0,7],0,[[10],[8,5],[3,3,6,2,7]]],[[[2,7],1,10,6],[]]] + +[[[],5,10,[7,0,[3,0,1,0]],6],[[[7,10,3,9],2,[5,6],3,[4,0]]],[[],[6,[3],[5,0,8,2],[0,9,10,5,5]]]] +[[9,1,0,4],[]] + +[[0,0,2,6,[[3],[3,4,7],[10,8,7,9],[4],4]],[[3,[]],8,[[10],8,3,[4,4,8],[0,2,9,7]]],[]] +[[[4,1],4,8]] + +[[[[1,9,4,3,8]],[[2,8,0,9,0],0,4,5,[2,9,5,1,8]],8,3],[[[4],1,8,[5,8],[4,0]]],[[0,7,[8,1,4,0,5],7],[[8],[],[0,8,5,7,5],6],0,[[4]]],[[],9,4,[6,[],[1,2,3,10],1],[[6,0],[8],5,6]]] +[[[5,[]],[],0],[[5,4]]] + +[[[6],[],1],[0,[7,1]]] +[[[6],5,4,10],[8],[[[6,0,1,4,4],7,[],6]],[10,4],[[[3],[0,0,1],3]]] + +[[[6,[9,10]],[[],3,[8,3],3,[3]]]] +[[[7,0,9,[8]],[[3,2,9,6,1],6,[4]]],[[[5,2,2],1,0,9],8,4,10]] + +[[2],[]] +[[5],[[[4,3,5],[5,9,10,6,7],[5],4,[9,7,6,2]],2,[]]] + +[[2,0,[[]]]] +[[[[8,2,8,8,6]]],[7,[[4,0,8,9,9],10,3,[],[5,7,6]],9,3,9],[7,[1,9],[6,[],3],10,1],[[]]] + +[[[2,10,7,[8]]]] +[[3,[[2,5,2]],[8],[],[[]]],[]] + +[[[5,7,4,0,[3,9,0,7,4]],[]],[7,4],[2],[[[5]]],[[[3,7]],[9],[5,[4,0],4,3,8]]] +[[9,[8,[],[2,3],[9,2,10]],[]],[1,1,[9,7,[0],[8,10,7,10,4]],8,[]],[7],[[7,[10,1,5,7,7],8,[3]]]] + +[[],[[[5,4,7,10,3]],0],[],[[4]],[[],[2,0],1,[[4,0,6,9,1],[5,5,0,8,9],[4],[]]]] +[[[],6,[7,8],1,0]] + +[[[4,[7,1,9,4,0],[10,8,8,3],[7,10,4,3,9]],2,[3]],[[[]],[9,[10],8,0,10],4],[],[[1,4,7,[]],3],[[[4,1],[4,0]],[[10,3],[10,7],1],3,[9,[3,6,10,4,3]],0]] +[[[0,[0,10]]],[[],[],[0,[],[1,0,5,3],1,7],[7,4],2],[[7],8],[[[7,8],[10,2,0,5,1],[8,6]]],[[6,[7],[1,5,1,5],9]]] + +[[[5,[7,8,0,6],0,4],[[6],1],[1,[0,0,6,9]],[10,[5,4,4],[8,9,7,8,1],[9,8,3]],[[6,7,5],10]],[[2]]] +[[[[4,4,1,0],[1,5,7,7]],[9,[6,7,6,7],7,[0]],2,[[3,1,4,4,5],[0,4],[3,5,7]]],[[3,5],4,5,3,6],[1,9,[[9,10,2,10],5,[9,9],[3,0,0],7],0],[5,5]] + +[[2,3]] +[[],[8,5],[[[7,4,4,10,8],[],[10,6,10]],8,4,1]] + +[[[[],8],[10,2,[],4,[5,9,4,3]],[[0,1]]],[1,10],[5,6,10,[10,[3,10],[]]],[9,[2,[0,7,1,8],5],[6],1]] +[[3,[8],3,[4,10,[5,10],3,10]]] + +[[0],[0,[[1,6,10],[5,3,10],1,[7,10]],1]] +[[],[5,0],[[4,[1,8,4],[8],[3,1]],6,[9,[3],10,8,[1,8,2,1,6]],3,[[8],0,4,6]],[[[10,1,1,9],0],[1,[],[1,6,8,9],[0,5,6,8,1],[2]],[9,[2],[9,0,4,6],[4,0,6,4]],[[9,9,5,9],1]],[2,[],[5,[2,1],7,[],10]]] + +[[10,1,9,6,[[8],5,1,[5,4],[5,0]]],[[[7,6,1],10,10,[2,8,5,3,1],5],7,[[2,5,6,7,1],5,[]]]] +[[6,[[10],[7,9,2,0],8],2,3,[]]] + +[[],[0,5,8,3,[]],[[5,5,[],[10,10,4]]],[8],[8]] +[[5],[7,2,5]] + +[[],[],[5],[]] +[[],[[2,[0],8],[[9,0,6,6,1],2,2,[0],[]],5,9],[[],3,7]] + +[[5,[[8],5,[5],[5,5],[10,5,9]],[[5,1],[1,10,6,8]],8,[[2,9]]],[[[0,8,5],10,[9,6,4],2,8],5,7,0]] +[[8,[8,[5,1,2,5],[5,10,6,5,3],0],6,10,1]] + +[[8,6,[[],[6,3],10,9],7]] +[[[4,[7,6,7,2,5]],[[10,4,8,10]],6,[[4,5,2,10,7]]],[[[1,9,10,6]],[9,[],[8,0,4,1]],10,6],[],[10,[[6,0],[1,9,9,10,5],[8,9],6,7],[1,9]],[0,[[6,3],8,[3],[],1],[[1,1],[],6,1,[10]]]] + +[[10,9,[4,[7,6,3],5,[]],[],[3,0,2,3,[10,6,10]]],[2,[[1,10],6,[9,5],[4],8]],[[[2],[2,8]],[2,1],6,[],4]] +[[5],[9]] + +[[[],[[0,4,6,4],2],0,5],[6,[[],5,2,2,[]],[0,[9,0,5]]]] +[[1,6,2,7],[2,5,0,2,[7,2]],[[9,9,2,[6,0,6,3,9]],[],[],0,8]] + +[[[4],5,[],3],[[[],5,5,[9,4,7,3]],[],3],[],[[2,4,[0,0],10,[]]]] +[[],[[[7,0,8],[6,9,0,0,2],[5,6,10,7]]],[4,8],[8,7],[[0,[0,10],[5],0,[1]],[5,0,[9,3,4,9]]]] + +[[[1],3],[],[]] +[[10,[[2,2],[6],[8],5]],[8,4]] + +[[9,[],8,[[9,4,10],5,3,[7,6,0,6]],2],[],[[3],4,[5],[8,[0,0,9,3],10,[],[]],[[7,6,7],9,[4,2,6],[0,7]]]] +[[],[3,2,[1,7,[3,1,10],[6,3,1,5,1],2]]] + +[[[3,[4,2,7,9],[8,7,2,10,8],[5,3,10],[9]],[[1,2,5],10,[5,4,7],[2,0,7,5],[1,4,3]],[2,[],3,[]]],[],[],[[5,10],6]] +[[[[5,10]],[[10],2,[9,6],[6,9]],1],[[[0,2,7,6,0],[3,4],[5,2],2,4],[],[2,[],[7,10,4],2],[[3]]],[[],[1,8,[7,0,1]],8,8],[[[8,1],[1,5,10]],[[2,0,8,4,2],2,4,7,[4,0]],9,[7,10,1],8],[5]] + +[[[4],[],[8],1],[[],4,0,4,[[2,5,7],0,[1,9,6,6],[6,2,0,0]]]] +[[1,[[3]],[2,3,6,[4,5,3,4]],8],[[],2],[5,0,[[8],[4,0,4,9]],[3],1],[10],[3,2,3,5,[10,9,[2,6,4]]]] + +[[1,[[5,8],[0,5,4],[1,8],9],9,[[5,4],[0,1,4,2,7],[7,1,8,5,8],[3,6,8],9]],[[[2,7,9,3],4,[6,2,1],7],4,10],[6,1,2]] +[[5,0,[[9],[10],[2,7,5],[7,6,6,5],2]],[4],[2,10,1,[[],4],[[],0,[0,4,8,7]]],[[[],8],5,[10],[4,[],7]],[]] + +[[[1,[4,6,6,5]],[[8,1,2,2,4],2,[1]],7,5,2],[8,2,3,2],[[],[5,10,4,[]]]] +[[3],[[]],[[10]],[[0,[3,9,10],9,6],10,6,6,1],[[4,8,2,2,[10]],[[]],[2,6],[0,[2],2,[8,0,1,2],3],5]] + +[[[[7,4,7,8,10]],[[10,7,8,5],[1,6,7,4,2],3,[5,7,2,4,2],4]],[4,10,6,1,[[8,0,5,8],1,[2,3,0,9,4],[6,10,1,9,10],[9,0,9]]],[1,9,5]] +[[[3,5,5],10,5,[],[[1,0,2],7,[1,1,2,9,2]]],[[],[[2,3,7,9],[],2,4,4],8,10],[],[5,[[2,1],3]]] + +[[7,9,9,[[7,6],8],5],[0,10,[3,5,1,[0,10,1,8]]],[[[10]],[8,[2,0,10,9,1],7,[8,1,7],[0,8,3]]],[[9,[0,0,9,3],[5,0,10,7,10]],[],[10,7],[],[[10,6,10],[10,3,4,8],1,[]]],[3,[],[[],[7,10],0],[]]] +[[[7]]] + +[[4,[4,[2,10,7,1,9]],5],[9,3,[[6,7,2,5],[4,7],[10,7,5],[5,9,5,9]]],[5,[],[10,[2,9],8,[]]],[[[6],8,3],8]] +[[9,[2,10,6,7],5],[7,[7,[6,10,2],[6,4,3,4]],8]] + +[[3,[3,[2,8,4,3],9,10,[]],[4]],[8],[[2,[8,0,0,9],9,5,0],9]] +[[[],8,[5,[0,0,10],8,0]],[[0,[5,4,8,5,10],10,[10,0],9]],[10,3,6,6,[]],[6],[9,7,[3,10,6,[3,2]],0,[3,[6,0,2]]]] + +[[7,[5,[3],2],1,2,[8,8,[1],3]]] +[[5,6,[[2],4,3],[9,2,3,9]]] + +[[],[6,8,2,7,3],[[[3,5,0,5,4],[0,0,3,8],[2,8,3,4],0],[],[[5,5]]],[9,[3,[],6,9,6],[5,[10,4,9,1,3],9]],[5,[],10]] +[[8],[1],[[],5,[[4,5],[],3],6,[[4,10,2,0],1,[4,7,8,10,10],[5,0,10]]],[2],[[5,[],[10],6,[2]],[[9,10]],[0,2,5],3,9]] + +[[6,3,6,2]] +[[],[[8,[7,3,4,3]],[[7,1],[2,0,9,3],3],9],[3,[[8,3,7,3],[2,4,3,0],5,[5,4,6,5]],2,0,7],[4,[5],[[],[],3],7,4]] + +[[[],6,[],[[9,8,2,3,8],4,[5],[1,0],[5,4,2,9,7]],[1]],[3,[]],[[[1,4],[4,8,7],[5,1,1]],[[9,9,0,5,4]],[9,[]]]] +[[[]],[[[3],9,4,[]],[[2,6,3,10],[5,8,9,5,8],[5,5,2,7,1],10,[2,8,0,4,10]]],[],[[[2,5,10,7],10,3],6,[[10]],[[5,3,0,7,1],6],4]] + +[[]] +[] + +[[8],[[[1,10],2,[5],5],[]],[[[8,5,2],[8,5],[5,10,4],[9,9,10],9]],[[[]],1],[4,[],[3,[],[10],3,[8,8]],[[9,4]]]] +[[[[8,8],[7,1,8,4],[8,2,1],[4,5,4],9],9,[],1],[[5,1],[[3],9,1],9,7],[[0,10,8,4,[0]],[[2,0,9,9,6]],0,3,10]] + +[[9,[[6,2,10],10,[6],[7,3]],4,8,[[1,1,9,2]]]] +[[[],[7,9],4,[[1,9,8,10],[5,1,5,4],[9],[0,0,10]]],[3,3,9,[[7],10]],[[[],5,0,5,9],[[10],1,[],1,[7,6]],9,1],[[[2,9,4,1]],4,4,[7,7,[7,3,9,8],[2,6,7,9,2]],[5,[],2,8,3]]] + +[[[[3,10,6,6,6],0,[1,2,3,3,9]],2]] +[[10,3,[]],[3,2,[]],[[10,[2]],5,8],[3,3],[[4,[],6,4,6],6,1,7,[3,4,3,[4,9,6,2]]]] + +[[5],[[6,8]],[7,0]] +[[[],[0,6,[],9],[[4,1,3,1],7,0],[6,[4,6],[]],[4,3]],[],[[8,[3,9],[],[5,10,4],[4,0,4]],[[7,4,10,4,2],[5,7,5],[5,1],0,[6]]],[4,[[2,3,0,0,6]],2]] + +[[8,6],[[5,[9,2,5,7,9]],[[5,9],[5,6,3,10],5],[[5,10,6,3,6],[3,1,4,1],[8,7]]],[[],[0,10,[1,3,5,6]]],[]] +[[8,[6,1,8,[],6],3,[7]]] + +[[1,8,3,[[2,2,0,4],3,[],8,5]],[5,[[6,3,1,9],6,9,[7,6]],5,9]] +[[[[2,8,2],9,[9],2],2,2,[],[6,6]],[[[],[4],[6,5,1,0,7],[9,5,5,1],[2,6,2]],[4,[0,3,3,5]],[]],[6]] + +[[[[3,7,10],1,[6,2,1,10],[2],6],5],[]] +[[3,3,3,[9,6,[],[10,8,9]],9],[10,[[8,9,8,6],[10,2],[2,7,2,0,1],3],[0,8,[]],10,7]] + +[[[9,7],[0,4,7,7,7],[[3,6,8,7,2],[],5,[2]],5]] +[[],[[[]],4,[[5],8,[],[],[10,1]],[],[3,2,[],9]]] + +[[],[5,1,9,1]] +[[5,[10,[10,4,10],[4,6],8,[5]],5,5],[[[]],1,1,[]],[3,5,3]] + +[[],[3,10,[3,[5],9,[]],[0]]] +[[[7,1],[[6,5],5]],[10,[5,7,[5,1],[]]],[[1],[4]],[6]] + +[[[[0,5,2],[6],[3,9]],[[10,3,2],3,[1,1,5]],9,[8,9,[9],10]],[[[1,9],0,9],1,[0,4,6],2],[[],4,[[],5]],[4,[6,[8],10],[],[[],[9],[1],[0,3,5,6],7]],[]] +[[3,[6,7,[],1,5],[8],[3]],[10],[1,6,10,6,[7,6]],[10,[[2]],7]] + +[[0],[],[2,4,2,[7,[7,2,0,1],5,1],0]] +[[[[1,7,3],6,3],9,9,[[0],4,5,[2,3,2,1],[6,4]]]] + +[[0,[3,[9,3,2],[7,9,10,4],[7,6,6,10]],[4,[5,7,0],5,1,6],10,[4,[9,2,9],0]],[5,[[10,9,4,0],1,[6],6],[2,9,[],[5,9],[]],[10,[],[],[1,4]]],[[7,9,[7,8]]]] +[[5,[10,2,[4,7],[]],[0,0,[7,4]]]] + +[[],[[8,[6,10,7],4],0],[],[4,0,[4,0],7,1],[4,10,[[9,7,3],[7,4,9,9,7],5,5]]] +[[[3]]] + +[[],[[1,5,[9,0,7,6,2],10,0],[]]] +[[[10,[10,8],[2,0]],6,4,10],[],[8],[]] + +[[3],[[6,[6,4,4,7,7],[5,4,6,4,7],[0]],[[9,4,10]]],[10,[10,[7,9,2,4],8,9,7],10]] +[[[[7],[7,2,4,8]],[3,[5],8,5],[[7,7,2,8,2],[1,10,8,2,10],[2]],6,[[9,6],10,[4]]],[5,[],[]]] + +[[5,[6,7,6,6],8,4],[[],1],[5,9],[[],5,6,7,[[6,8],10]]] +[[],[[],8],[4,6]] + +[[4],[]] +[[],[],[1],[[[7,7,1],[1]]],[[[1,9,5,0],4,5],1,[8,0,[7,4,8,1]],[[9,0,9],9,[4,5]],[0]]] + +[[[[],8,9,[6,5,7]]],[[[8,10],[0,9,8],5,4],[[10,8,8,3]],[[3,4,1,5],9,[],[4,10,10],3],8],[0,9],[[9,[8,1,10,1],[10,1,4],[3,1,10]],[7,9]]] +[[[1,[6],1],[[],4],3,9,5]] + +[[1,6,[],4,[7,10,1,[7,9,7,1],5]],[10,6],[0,6]] +[[[[3,7,9,5,7],7,4,10,4],4],[],[[[10,4,1,2,4],6,[1],7,[]],[[5,8,5]],8,[[5],[],[10,3,1],[6,7,6,5,10]],[8,[7,4,5],[2,8,10],[]]],[3,9,[[8],3,[0],2],7,[2,[0,3,7,5,4],4,8]]] + +[[[],[[6,7,3],[5,6],7,[7,1,8,3,10],[5,6,8,4]],8],[[[10],[5],[6,0,10],9]],[[[],[9,8,8,9,2],[2,5],[4,6,7,5]],10]] +[[[1,1,0,[9,6,3,10,7],2],2,10,[8,8,3,[10,10,5,4,7],[]]],[10],[5,[6,3],3,6,1],[[2,[6,10,10,9],[2,7],8,[2,0,7,10]],7,[],[5,[2],[],4,9],[1,[10,3],[]]]] + +[[[[0,1,7,7],9],8,4,[],[]]] +[[[7,[10,3]],[8,1]],[10,9,7,[[1],[6,9,2],8,1,[5,7,3,5,10]],[[]]],[[[9,3,9,10,9],0,[6]],1,[2,[5,8,4,5,5],9,[4,10],2],0,[4,[0,1],10,[6,9,9]]]] + +[[[3,7,[1,9,9,1,7],4],[],[[6,10,1,1],9,[9,9],8,0],4,[[],[7,8,0],9,[7,6,4,0,9]]],[[9,7,3],[[2,6,5,5],[]],[[9],[7,5,0,8],[9,9,1,1,0]],7,3],[5]] +[[[[10,2],10],7,6,[[10],[5,4],0,4,[8,5,4]],[[],1]],[4,8,[3,1,[0,8],[3],6],[[3,4,3],[6],[4,5,4]]]] + +[[[0,[9,6,6,8],0,[3,7]],[[3,2,0],[3],[4],[6]],4,3,[7]],[7,[[],[],8],6,3],[],[1],[5,9]] +[[[7,[6,4,7]],[[2,5],10,[6]],[[],[]],[1,[9],6,9,[0,7,4,3]],1],[1,[8,[7,8,1,9],[10,3,3,4]],[[4,7,3,0,3]],[[1,6,6],6,5]],[]] + +[[6,[5,6],5,8],[[[5,8,4,9],9,[1,8],3,[9,5]],[]]] +[[3],[1,[10,0,[2,7,3,8,2],[10,3,9,4,2]]],[[[10],[8,2,10],5,2],3,[3,[8,0],3,5,4],[],3],[],[[9,8,9]]] + +[[[5],7,[[5,8],[3,9,3]],[[4,5,3,3],[4,5,1,2],4,9]]] +[[7,[2,[3,3,0,5,3],10]],[6,5]] + +[[[3],[[9,1,2]],6,5],[8],[10,[[1,5,2,10,7],[],[10]],5,6]] +[[7,10],[[],5],[],[10,[6],[10],[[],10,9,[1,2],[0]],6],[6,0,[7,[3],[8,9,2],5,3]]] + +[[[[0,2,2,0,8],1],1]] +[[[],[[1,1,6,10,3],9,1],[[2,2],8,3,1],[[9,0,6,1,0],[3,3],7]],[],[[7,[1],[3,4,9,0,0],8],7,[9,[],[8,0,8],10],[[3,8],6,[8,0,10],[9,0,1,0,8],5]],[[[2,10,5,3,2],[2,5,7,9],[3,4,4,3]],0,2,[[]],3]] + +[[1,7,[[6,7,7],1,[4,3,10,1],3],0,3],[2,[]],[],[7,[[0,4],[5,8],7],[[7,10,3,9,5],[6,5,1,6,6],10],[2,0,[6]]],[]] +[[[[7],5,[]],8],[3,4,7],[[],[2,[6,7,7,0],[5,0,1],[7,5,1]]]] + +[[0,[],1],[[[10,0],[5,2],6],9,[[10,8,2,7,3],[4,8],[2,5,3,7,2],[9,4,3,9,9]],3,9],[]] +[[],[[[],[1,3,3,6]],[4,[2,6],4,[8,5]],[5],7],[[],[[],0]],[3,[[0,2],[1,4],0],6,3],[[],[[9,7],[],[7,3],[],7]]] + +[[[7,[2,3,3],5,8,9],[[1,8,6,7]],6,[8,[0,8,0,7,10],[8],[6,9,1],1],9]] +[[7,4],[[[8,7],3],[0,8,9],6],[8,[3,[],5,[10,0],2],[1,2,[9,4],0]],[[],[],10,[[3],4,2]],[10,[8,7],4,[[3,3,5,6],[],[9,8,4,1],[0],10],[]]] + +[[],[[[5],[3,7,7,0],[4,9,6,6]]]] +[[[[],[5,5,10,4]],8]] + +[[4,9,[],4]] +[[8,3,10],[[[1,1,1],[10,3],[9,1,10,3,4]],10,10,4],[[[]]]] + +[[1,[6,4,6],[],0,[[],[]]],[8,3,[2],7,8]] +[[8],[1,[],[2,[4,9,3],5,3,7]],[],[[[9,6,1,4],[9],0,8]]] + +[[[[9,7],[0,4,5,7,3],[10,8]],[[10,6,9,4],0,3,[9,2,5,8],[5]]],[[0],9]] +[[[[5,7,1,1,7],5,[],2],[3,[4],7,[9,0,9,1,0]],[[8],[10,3,10],[1,1],10,[5,3,7]],10],[[6],1],[[[],[4]],3,10],[]] + +[[[2,8,4,[8,7,6,5]],5],[10],[7,[]],[[9,7,10,0]],[5,9,[],[10,2,[2,2,7,0]],4]] +[[[[10,7,6,1],[]],[2,[],10,2,1],0,[[2,9,9,9,1],3,8,[9,7,6,3],2]],[4,[[3],9],8,[10,[6,9],[6,6,6,8,7],2,6]],[7,[[6,7,8],[5,2,8,7,9],[],8],0]] + +[[[4,10],8,10,8],[3,1,[2,7,[7,10]],2],[[2,0,3]]] +[[6,8],[10,[[1],7,7,10]]] + +[[[],[10,9,8,0,5],4,[],0],[[[1,8,6],8,[2,10,9,8],7],[7]],[2,[[9,8,5,4],8,[],[]],[[]],9,[2,4,[3,3,9,10]]],[]] +[[2],[[[6],[3,2,0],[3,8],[3,8,8,3,0]],6],[2,[10,[],9,[],[7,3,9,2,4]],3,2,1],[8,3]] + +[[4,[9],[[9,10,4,7,2],8,[1,9,0]],[3,6,9,9],[[3]]],[]] +[[[8],[7],[1,1,[7,10,7,5,2]],[[4,5],[9,10]]],[[],2]] + +[[[[7,9],[0,6,8],8,5,[1]],4,[6,1,[1,2,3,3,9]],10,7],[4,[[],3,5],7,[10],0],[4,1,5],[0,9,[[10,5],[0],9,[0,7,4,2,10]],5,9]] +[[[[9,9],1,10,[9,7]]],[1,[[1],[2,4,9,0]],[4,0],7],[[3,[1,3,4,7],5],2,[[]],[[5,4]]],[1,4,9,10]] + +[[[6],[[2,4,10,8,1],[0,5,1,10],2],[0,1],[[8]]],[[2,[4,0]],[[]],[3,2,0,[8,8],[0,5,10,6]],1],[2,9,4,6,[[8],[9],10,[5,5],[5,5,9,8]]]] +[[[[6],6,[4,9,4,9,4],[7],[1,0]],[]],[[[],3],[[0,3,3,2],6,[2,6,6,8]],[[6,10],8,4],6],[1,5],[[],10,[]],[[[6,7,5],[4],[]],2,0,[[],[10,3,2],1,2]]] + +[[10,[[1,3,1,1]],3],[7,[[4,9],[5,4],3],10]] +[[[[],1,[9,7,2,10,6],10,6]],[1,[0,[3,8,0],1,2,[8,6,4]],2,[[7,5]],[[],[3,8,7,1],[],2]],[[],4,1],[[[6,2],[7,0,2],1,[10],[3]],[],[0,[10],[2,2],0,2],[0,[7,8]],2],[[2,2,[5,10,10],[0],[]],0,0,[[],1,[8,10]],5]] + +[[7,[8],8,5,[8]],[],[1,[[3,7],10,6],[7,2],1,[[1,3,1,7],10,[7,3,10,2],5]],[],[]] +[[8,3,8,[5,10],4],[[[],[2,3,8,1,6],2,[0,10,2,3,7]],4,1,10]] + +[[[5,9,6,1],[10]],[[2,5,[6,4,4],[2,4,2],[8,5]],7,[4,5,[0],4]],[3]] +[[8,[],2,[[10,5,2,5,5]]],[[[],[1,9,0,8,2],5],1,[7,[8,7,3],[5,0,5],[6,2,3],2],[1,10,0]],[6]] + +[[2,6,[[9,3,4,7],[9,3,9,1,2],3,4,0],2],[[[],[9,10,7,0],[]],[[2,6],[7,9,9],2,[7,3,2,7,8],[9,5,5,6]]]] +[[8,[[2,0],7,[7,4,9,10],7],[5],[2,[4,5],5],4]] + +[[0,10,3,9],[[[3,5,3,0,4],[5,8,5,3],9,[0,3,4,3]],10,6],[3],[5,0,10,[[2,1],6]],[3,[2],[[4,1,1,7,9],[3],3]]] +[[9,[1,6,1,4],3,2,[[],3,[6,8],[3,4,8,0,8]]],[10,[9],8],[3,3,7,2,[]],[9,[[7,0,6,9,7],[0,1,9,2,9],[4,6],9,[9]],[]]] + +[[[[4,5],9],[[],6,2,5,[0,7,0,1,8]],[5],4],[[[3,7,10,9,3],[],[],3]],[0]] +[[[[],7,[3,9,5],9],0],[[3,[],8],[6],3,5],[1],[[[],[]]],[[5,10,[2,9],[1,8,9],[4,3,1,1]],1,[[],[2,10,9],9,6],[[3,7,9,3],[0],[5,0,5],[2,7,3,5],[0]],[3,[],[5,10,0],9,[7]]]] + +[[8,2,[],[5,7]],[4],[[[8],7,6]]] +[[5,[[0,10,5,9],4,[0,10]],0,5,10]] + +[8,4,9,3,2] +[8,4,9,3] + +[[[[5]]],[[1,0,8,6],7],[7,1],[4,6],[[9,2,[0]],[[4]],[7,1,0,[10,10],10]]] +[[0,[[10,0,5,5,2],1],9],[[[1,4,3,3,5],[6],0,[2,4,9,8],[4,8,4]],[10,[0,2,7],[9,8,5],[],9],[3,[],1]]] + +[[[1,7,[1,1,1,9]],[4,1,[8,4,2,1]],[],[]]] +[[[],[[],[7,9,7,2,6],9],[[6,6,3],[8],3,0,3],7,[3,[0,2,3,4,0],[5,7]]],[8,[1,6,5,7]],[[7,[],[4]],[8,[],[8,6,7,4],4,6],[],[9,[2,2,6,7,6],7],9],[[[],8],10,[[],[8,2,8],8,[5,1,8]],[],[3,5]],[2,1,[7,[0,6,5,6,6],[5,7,4],[5,0,4,5,10]]]] + +[[],[[[3,7],4]],[],[],[[[2,0]],[5,9]]] +[[[6,4,[10],8,5],5,[7,[4,4,0]],[6],5],[2,10,[[2,10,5,8,5],[10,5,7,2,8],4,[8,5,5]],8,[[3,3],[6]]],[3,[[0,8]],1]] + +[[0,5],[[],4,8],[],[],[[1,[]],5,1,[[]],0]] +[[[]]] + +[[],[],[8],[],[6,10]] +[[3,3,6,8]] + +[[[0],[9],9],[[10,10],[7,[6,3,1,10,7],[5,7],[6,2,5],2]],[5,[2,[7,3]],6,3]] +[[],[9,[[4,9,9,9,6],[],[10,5,6]]],[[[1,7,0],[5],4,[],0]]] + +[[2,[5,10,[2,8,5,1,5],[9,0,8,0],8],[[8,8,10]],8],[2,[8,10,[],[1,5]],5,[[7],[4,2,1,1,8],0,1,[10,8,2]],2],[10,[[8,8,4,7,5],[5,7],10,[8,0]],5,[[4,4,2],[2,4,3,0,1],[7,8]]],[6]] +[[9]] + +[[4,[4,[0,7,0],[1,5,10,5],[2,10,7]],[5],[[2,4,2],[3,8,7,6],6]]] +[[7,7,5,[[4,8,10,6]],5],[2,4,10,1],[[[10],[10,9,2]]],[],[[[3,1,3,1],[],[0,0,9]],9,[2,[2,5,10,1,5],9],5,[2,[5,1,4,2],10]]] + +[[3],[8],[8,[4,[2,10],9,[4,10]],[],[],8]] +[[[[],[10,10]],[3,[5,3,4,5],8],9,[2,5],8]] + +[[],[],[[[8,8,4],2,[],5,3],[],[[2,2,0,0,10],[1,2],[1,1],8],[[10,6,1,6]]]] +[[[[1,0,4,7,8],[2,5],[3,1]],9,9,[[10,9]],[[2]]],[[[],[3,3,10],[8,7,5,4,9],6,0],2,[8,10,4,[8,3,3,9,2]],[[7,10,10,0,0],[4,3,8,3]]],[[1,0],0,6]] + +[[[]],[2,[[9],1,[6]],6],[[[10,0,0,9,2],[1,8,4],9,[10,6,5,2],[3,0,0,8]]],[5,[[],1,[4],[]],0,10,[2]]] +[[9],[],[[0,3,9,[]],[2,[1,9,0,0,4],[9,10,1,9,4],[]],[10,3,2],9]] + +[[[2],[1,1,[6],[8,6,9,6,7],3]],[[],8,[[6,6],[5,8,10],[],[9],8],[]],[]] +[[1,9,2,[6],[0,0,3]],[]] + +[[10,5],[],[[[]],7],[10,8,8,9,[[],[1,3,9,2,8],[9,4,2,6,7],[8,6],7]]] +[[[5,[2,8,0,6],[0,7],0],[[],[]],2,[6]],[[],4,6,[[],[4,8,8,7,5],7,[],[]],7],[4]] + +[[10,[[4,10],[8,1,10],[4,9,8,1,5],3,[4,9,1,1,6]]],[],[[7]],[[[],0,4,[7,6,4]],2,[[4],10],2,0]] +[[[],5],[2,[],7],[9],[]] + +[[],[],[7],[10],[]] +[[2,[[3,0,4,8,10],1,5,[]],[4,[9,4,10,7,2]],3],[8],[[[6],4,[3,7,5,9]],8,6,[10],8]] + +[[],[6]] +[[[[9,9,3,10],[5],9,6,3],[8,7,4,0],[],[[5,9,9,0],[],[1],[2,4,8]]],[10,[[9,6,4,1],1],0],[[9,[],7,7,6],[9],6]] + +[[[10,[5,10,0,7,2],[2],8]],[[9,9,[],1,8],[[],[1]],[5,[3,3],1]]] +[[],[3,1,[10,[2,2,10,0],[4,3,3,6,7],8],8],[[[8],2,4],[[],[],10,2,[]],6,8,8],[[7,0,8,[]]]] + +[[[4],7,[10]],[[[3],1],2,[9]],[[4,7],[[3,8],[2,5,5,4],5,[9,6,2,2,9]],2,[[4,5,8,6]],[0,6,7,[4,2,1,7],2]],[6,5]] +[[[9,1,3],[[9],8,[5,1,7],[9,8,9]],5,[[1,1,10],3],2],[[5],7],[]] + +[[3,[0,5,[8],[],[]],8,7,9]] +[[8,[[2],3,[],7,7],3],[[[2],[7,9],[8]],[6]],[[[],[6,5,0,5,2],[6,4,4],[5,9]],[[0,2],[10,8],[6,2,1],[4,10,6,8],6],[[1,1,8],9,5,5,[3]],[],[0,[],[1],[2,5,10]]],[[],5],[[[8,0,7,1,4],3,[],4],9]] + +[[],[9],[5,[[2,0,0,10,6],3,7,3,[9,9,2]],7]] +[[[],9],[],[6,6,[9,2,[3,6]],[[3,2,6,2],[9,0],0],1],[[9],10,[9,7],[9,[10,6],0]],[[[8,0],8,[1,10,2,9]],8,5]] + +[10,8,0,10] +[10,8,0,10,6] + +[[[[7,10,2],7,[]],[[],[1,0],[],[],3],9,2],[[[],4,9],0],[3,3,[],2],[[3,[7,1,1],3],10,10,9],[[6,0,3,[],[3,6]],[[9,10],[9,1,7,3],10,9],10,1]] +[[],[6,9,[0,3,3,0,[7,9,8]]],[[3,[8]],[8,[6,3]],2]] + +[[[2,[7,10,4,7,3],[9],0,4],1,[2,9,8,2,6],9,0],[],[3,0,[[5,4,4,2]],2]] +[[[[3,0],[5,9,9],[2,5,0],2,3]],[2,[6,[5]],[[10,3],8,9,[9,5,10,8,2]],8],[]] + +[[0,[[10],7],2,2,1],[[[0,2,5],2,7],[10,[],[8],7],5,[[2],0]]] +[[],[3],[10,[4,[5,2,7,3],9,5],3,3,6],[[7,[]]],[[[10,7,6,6,4],[4,2],8,6,[3,5,0]]]] + +[[0,[0,[],[]],5,0,9],[[7,9,[],[1,6,0]],[[10,6],3,[3,1,10,5,8],[]],7,6],[4,6,[],0,2],[5]] +[[[5],[8,0,5],[7,[1,3,9],3]],[2,7,0],[],[4,[4,8,4,[5,9,0]],[]],[[[10,7,6,1],[4,5,8,7],9]]] + +[[[9],1],[[4,[5,6],[4],5],10,6,[7],6],[[[5,4],[8],[7,4],[6,2,9,8],[4,0]],1,[[]],3,[10,0,1,[3,2,3,5],4]]] +[[7],[4,[3,[4,3,1,9,6],1,[]],[1,[6],[0,3]],0,10]] + +[[[0,3],[3,[1],[],6,[]]],[8,[],6,[],4]] +[[[[4],5,[9,1,7,9,9]],[2,5]],[[[10,8,5,10,2],7,[0,6,10,3],10],3,[6,0,[3,5,0,5],[8,9,3,5]],3],[[[0,4],[10,6,7,5],7,[10]],[1],[[8,10],2],[[],10,9,0]]] + +[[6,[[1]],1,[[],2,[6,10],6,1]],[[7,3],3,6,[3,3,10,[0]]],[6,[[6,7],5,1,[4,2,0,1]],10],[9,[[9],[2,6,5,1],0],[7]],[[[5],[],7,9,[10]],[[7,0]],[[]]]] +[[4,1,4,[[5,4],[9],[],[3,8,5]]],[2,8,[[6,6,4,6]],[4,1],1],[[2,0,[7,7,2,1,4],[0,8,3,8],9],5,0]] + +[[[6,10,9,[1],8]],[4,0,[[8,1,9,7,0]],[[3,7,10],9,[10,9,2],[6,10],[5,9,5,10]]],[5,5,8,1,2],[]] +[[7,2],[2,7,2,5,[[1,4,7,10,10]]],[8,4,[[9,8,10],[0],2,[3]],1,7],[2,0,[0,4,0],5,[]],[[[6,8,9],[2,4,3,4,10],10],2,9]] + +[[5,8,[],[[8,6,3,10],[1,1,4,7,5],[1,8,0,5,2],6,5]],[],[]] +[[],[],[[[5,9,6],2,10,[9,1],4],4,3,[1,[9]],6]] + +[[2,[2,[7,8],[7,2,0]]]] +[[0],[[],7],[],[],[1,[7,[4,6,9]],4]] + +[[[[9,6,7,5],2]]] +[[[],8,[3,0,5],1,8],[[[3,5,7,7,7],[6,3,7,7],[1,1,2,1]],0,4,[0,5]],[],[2],[[7,[6,4,8,7],[8,8,10,5],1,10],10,8,[[8,1],[8,5,5],3,[8,0]],6]] + +[[10,4]] +[[],[0,[],[[],[8,1,0],[10],[0,6,6,9],8],2],[[[9],1,[]],[[2,0,8,10]],6,[[2,1,10,3],[],8]],[2,[[8,4,0,5],0,9,5,[1]],[]]] + +[[10,0,10,9]] +[[[2,[10,3,6],4],[[6,5,10,3],8,[0,0,9,7,2],[10,4,5,4,4],[1]],[1],[[3,7,4,10,1],[8,10,4]],9],[10],[[5,5,[1,7,10],9,4],[],3]] + +[[7,4,1,[6,8,4],10],[5,10,7,[9,10,6,7]],[4,3]] +[[[4,[9],[7,1,3],5,[]],2],[8,0],[[[9,0,5,4],[4,0,8,5],1],7,[8,3,[],9],0],[]] + +[[[1,3]],[[[1,3,4],0,[9],[0],[8,5,8]],[[7,4],0,[2],[2,1,0,0]]],[[],[[2,1,3,3],6],[3],[[1,6,8]]],[9,2,[[],[4,7,7],[7,2,10,6,3]]]] +[[10]] + +[[[],[]],[6,[5,6,[1],0]],[10],[[10],1,[8],7,8],[[[],8,4],3,3,[1,[2,7]],1]] +[[[7,8,[1],2],7,[[0,6,4],3,[6,8,7,6,5],[2,10,6,4,4],1],[[6,6,9,2,9],[6]]],[6,[]],[[1,[],[6,5,8]]]] + +[[[[8],4,[0,10],[],[5,5,8]],10],[],[7,[],[],[[2,10,1,4],[9,9,4],1,7,[8,5]]]] +[[7],[[],[[10,3,1,4,3],6,[5,9],[0]],1],[4,0,[[7]],0,3],[10,5],[[8]]] + +[[[],3]] +[[1,3,[[8,7,9,5],[],7,[],6],[9,[]],8],[[[1],[4,3,1],6,[9],[6,4,0,4]],[[8],1,[0,10,5],7,6],7,[2,[6,9,5,9,1]]]] + +[[[9,[0],[9,0],0,9],[],[[],[1,1],[5,7,7,5,7],[]],1],[[8,5,7],8]] +[[6,[],[0,2,1],[3],2],[7,7],[6,[],[],2]] + +[[5,4,[[7,8,3,0],[3,9,7,1,10],[10],6],1],[]] +[[8,6,[[2,2,6,8],[1,2,2,7],[],[],7],2,6]] + +[[[[],[5],[],9,3]],[],[7,[],0,[[8,8,10,8],10]]] +[[5,10,2,7,5],[6,5,3],[2,[[3,1,2],2,[]],1],[4]] + +[[],[],[]] +[[[[4,2],[7,1,1],6,9,[9,5,8,2]]],[[],[[7,10,9,1,0]]],[[[8,8,8],1,[7,10,3],10],2,1,[[5,4,5],[10,4,0],4,5]],[4,2,[]]] + +[[[[],3],[[10,6,10,6,4],2,[9,9,2,0]],[6,[],[10,8,2,6,10],[8,8]]]] +[[[[1,5,10],[7,0,4,2],7,[]],0],[2,[8],10,1,6],[7,[[5,5,4,7]],6],[[[8,7,7],8,[0,5,6,10,9],10],7,[2,6],[],6],[1]] + +[[[[4,0,6,6],[5,6,7],[10]]],[7,9]] +[[[7,8,[0,8,10,1],4,10],10,[[8,1],1,[],3,6]],[]] + +[[9],[[],5],[8,[4,0,[9,7,0,3,8]],[]],[5,6,9,[1,[1,10,3,1,6],10,2]],[[],[],5,[[7,5,4,7,7],5,6,[10,9,1,9,2],0],[]]] +[[[[9],10,[9,0,9],5],10,4,6],[0,[1,6],2,3,1],[3],[[],[[0,7,0],[7,1],4,3]],[3,9,[],8]] + +[[1,2,6,2]] +[[[[5,1,0]],10,[10,[],[9,0,5,4],1],[5,6],[[9,6,6],0,3,[0,4],6]]] + +[[[0,[7,8,3,10,1]],6,2],[8,[[1,5,3,1,10],[0,1,9]],5,[10,1],2],[[[7,8,1,0],0,[10,7,3,3],[4]],7]] +[[0,2,[[10,1,3],2,4,0]]] + +[[[6,[5,2,3,6,8]],[[9,7],[6,10,8],4,3,[3,1,9,4]]],[3,[[7,8]]],[7,0,[6],1]] +[[[],6,7,[4,1],[6,[],[4,7,0,0,6],[9,2,7,9],0]]] + +[[[4,[9,6,8,9,7],[10],[4,6],[2,10,7]],[],[[],4,6,2,0],6,[[6,5,3,10,2]]],[9,10,0]] +[[4,[6,[0,1,5],5]],[8],[4],[[],[0,[2,5,4],[]],[[0,5],[0,2]]],[[3,[10],[6]],4,[],3,[[2,1],9,1,8]]] + +[[[],4],[0,2],[[[7,2,3,5,7],[3,3,9,5,0],[1,8,3],2],[[10,10,5,7,10],[],[5,10,10,1,3],[4,9],[3,5]]],[],[9,3,[2,3,[1,7]]]] +[[9,2,8,3],[[[1,6,9],9,9,[],[6,7,9]],9,0],[1,8,[[]],5],[[[3,7,0,9],[2,3,4,6,2],3,[3,3,0]],3,[3,2,1,[8,4]],[4,[10],4],[[5,10]]],[]] + +[[[6,8],9,6,9,5],[9,2,[]]] +[[[7,6],[]],[0,[[2],5,4,[]]],[8,6,7],[[[],[4,2,3],[0,3,2,7,5],[0,2,4,1],0],3],[5,7,[[8],5]]] + +[[6],[[3,4,[1,1,4],6]],[[[]],[],[10]],[2,6,[10,9,1,8,[0,5]],6],[5,7,[[6,10,2,3]]]] +[[[[2,4,0],9],4,8,[[],[9,4]]],[]] + +[[[[9,6,3,8],10,4],[10,[0,4,10,0,2],[6,7,10,1]],[[],[6,9,6,9,8],[],5],3,[4,4]],[[[],[9],[],5,5]],[]] +[[6],[3,[9,0,6,[9,6]],[[2,5]],[]],[[[7,7,6],[0,1],0,[]],5,1,3],[8]] \ No newline at end of file diff --git a/day13/problem.md b/day13/problem.md new file mode 100644 index 0000000..b3b731a --- /dev/null +++ b/day13/problem.md @@ -0,0 +1,153 @@ +--- Day 13: Distress Signal --- +You climb the hill and again try contacting the Elves. However, you instead receive a signal you weren't expecting: a distress signal. + +Your handheld device must still not be working properly; the packets from the distress signal got decoded out of order. You'll need to re-order the list of received packets (your puzzle input) to decode the message. + +Your list consists of pairs of packets; pairs are separated by a blank line. You need to identify how many pairs of packets are in the right order. + +For example: + +[1,1,3,1,1] +[1,1,5,1,1] + +[[1],[2,3,4]] +[[1],4] + +[9] +[[8,7,6]] + +[[4,4],4,4] +[[4,4],4,4,4] + +[7,7,7,7] +[7,7,7] + +[] +[3] + +[[[]]] +[[]] + +[1,[2,[3,[4,[5,6,7]]]],8,9] +[1,[2,[3,[4,[5,6,0]]]],8,9] +Packet data consists of lists and integers. Each list starts with [, ends with ], and contains zero or more comma-separated values (either integers or other lists). Each packet is always a list and appears on its own line. + +When comparing two values, the first value is called left and the second value is called right. Then: + +If both values are integers, the lower integer should come first. If the left integer is lower than the right integer, the inputs are in the right order. If the left integer is higher than the right integer, the inputs are not in the right order. Otherwise, the inputs are the same integer; continue checking the next part of the input. +If both values are lists, compare the first value of each list, then the second value, and so on. If the left list runs out of items first, the inputs are in the right order. If the right list runs out of items first, the inputs are not in the right order. If the lists are the same length and no comparison makes a decision about the order, continue checking the next part of the input. +If exactly one value is an integer, convert the integer to a list which contains that integer as its only value, then retry the comparison. For example, if comparing [0,0,0] and 2, convert the right value to [2] (a list containing 2); the result is then found by instead comparing [0,0,0] and [2]. +Using these rules, you can determine which of the pairs in the example are in the right order: + +== Pair 1 == +- Compare [1,1,3,1,1] vs [1,1,5,1,1] + - Compare 1 vs 1 + - Compare 1 vs 1 + - Compare 3 vs 5 + - Left side is smaller, so inputs are in the right order + +== Pair 2 == +- Compare [[1],[2,3,4]] vs [[1],4] + - Compare [1] vs [1] + - Compare 1 vs 1 + - Compare [2,3,4] vs 4 + - Mixed types; convert right to [4] and retry comparison + - Compare [2,3,4] vs [4] + - Compare 2 vs 4 + - Left side is smaller, so inputs are in the right order + +== Pair 3 == +- Compare [9] vs [[8,7,6]] + - Compare 9 vs [8,7,6] + - Mixed types; convert left to [9] and retry comparison + - Compare [9] vs [8,7,6] + - Compare 9 vs 8 + - Right side is smaller, so inputs are not in the right order + +== Pair 4 == +- Compare [[4,4],4,4] vs [[4,4],4,4,4] + - Compare [4,4] vs [4,4] + - Compare 4 vs 4 + - Compare 4 vs 4 + - Compare 4 vs 4 + - Compare 4 vs 4 + - Left side ran out of items, so inputs are in the right order + +== Pair 5 == +- Compare [7,7,7,7] vs [7,7,7] + - Compare 7 vs 7 + - Compare 7 vs 7 + - Compare 7 vs 7 + - Right side ran out of items, so inputs are not in the right order + +== Pair 6 == +- Compare [] vs [3] + - Left side ran out of items, so inputs are in the right order + +== Pair 7 == +- Compare [[[]]] vs [[]] + - Compare [[]] vs [] + - Right side ran out of items, so inputs are not in the right order + +== Pair 8 == +- Compare [1,[2,[3,[4,[5,6,7]]]],8,9] vs [1,[2,[3,[4,[5,6,0]]]],8,9] + - Compare 1 vs 1 + - Compare [2,[3,[4,[5,6,7]]]] vs [2,[3,[4,[5,6,0]]]] + - Compare 2 vs 2 + - Compare [3,[4,[5,6,7]]] vs [3,[4,[5,6,0]]] + - Compare 3 vs 3 + - Compare [4,[5,6,7]] vs [4,[5,6,0]] + - Compare 4 vs 4 + - Compare [5,6,7] vs [5,6,0] + - Compare 5 vs 5 + - Compare 6 vs 6 + - Compare 7 vs 0 + - Right side is smaller, so inputs are not in the right order +What are the indices of the pairs that are already in the right order? (The first pair has index 1, the second pair has index 2, and so on.) In the above example, the pairs in the right order are 1, 2, 4, and 6; the sum of these indices is 13. + +Determine which pairs of packets are already in the right order. What is the sum of the indices of those pairs? + +Your puzzle answer was 6420. + +--- Part Two --- +Now, you just need to put all of the packets in the right order. Disregard the blank lines in your list of received packets. + +The distress signal protocol also requires that you include two additional divider packets: + +[[2]] +[[6]] +Using the same rules as before, organize all packets - the ones in your list of received packets as well as the two divider packets - into the correct order. + +For the example above, the result of putting the packets in the correct order is: + +[] +[[]] +[[[]]] +[1,1,3,1,1] +[1,1,5,1,1] +[[1],[2,3,4]] +[1,[2,[3,[4,[5,6,0]]]],8,9] +[1,[2,[3,[4,[5,6,7]]]],8,9] +[[1],4] +[[2]] +[3] +[[4,4],4,4] +[[4,4],4,4,4] +[[6]] +[7,7,7] +[7,7,7,7] +[[8,7,6]] +[9] +Afterward, locate the divider packets. To find the decoder key for this distress signal, you need to determine the indices of the two divider packets and multiply them together. (The first packet is at index 1, the second packet is at index 2, and so on.) In this example, the divider packets are 10th and 14th, and so the decoder key is 140. + +Organize all of the packets into the correct order. What is the decoder key for the distress signal? + +Your puzzle answer was 22000. + +Both parts of this puzzle are complete! They provide two gold stars: ** + +At this point, you should return to your Advent calendar and try another puzzle. + +If you still want to see it, you can get your puzzle input. + +You can also [Share] this puzzle. \ No newline at end of file diff --git a/day14/day14.test/UnitTestProblem.cs b/day14/day14.test/UnitTestProblem.cs new file mode 100644 index 0000000..ec74d91 --- /dev/null +++ b/day14/day14.test/UnitTestProblem.cs @@ -0,0 +1,22 @@ +namespace day14.test; +using FluentAssertions; +public class UnitTestProblem +{ + [Fact] + public void TestProblem1() + { + var problem = new Problem(); + problem.ResolvePart1("testdata.txt"); + + problem.Result1.Should().Be("24"); + } + + [Fact] + public void TestProblem2() + { + var problem = new Problem(); + problem.ResolvePart2("testdata.txt"); + + problem.Result2.Should().Be("93"); + } +} \ No newline at end of file diff --git a/day14/day14.test/Usings.cs b/day14/day14.test/Usings.cs new file mode 100644 index 0000000..8c927eb --- /dev/null +++ b/day14/day14.test/Usings.cs @@ -0,0 +1 @@ +global using Xunit; \ No newline at end of file diff --git a/day14/day14.test/day14.test.csproj b/day14/day14.test/day14.test.csproj new file mode 100644 index 0000000..d1dc0cd --- /dev/null +++ b/day14/day14.test/day14.test.csproj @@ -0,0 +1,32 @@ + + + + net6.0 + enable + enable + + false + + + + + + PreserveNewest + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + diff --git a/day14/day14.test/testdata.txt b/day14/day14.test/testdata.txt new file mode 100644 index 0000000..1926028 --- /dev/null +++ b/day14/day14.test/testdata.txt @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 \ No newline at end of file diff --git a/day14/day14/Point.cs b/day14/day14/Point.cs new file mode 100644 index 0000000..5e59bd2 --- /dev/null +++ b/day14/day14/Point.cs @@ -0,0 +1,26 @@ +namespace day14; + +public class Point : IEquatable +{ + public Point(int x, int y) + { + X = x; + Y = y; + } + public int X { get; set; } + public int Y { get; set; } + + public override string ToString() + { + return $"({X},{Y})"; + } + public override int GetHashCode() + { + return this.ToString().GetHashCode(); + } + + public bool Equals(Point other) + { + return this.X == other.X && this.Y == other.Y; + } +} diff --git a/day14/day14/Problem.cs b/day14/day14/Problem.cs new file mode 100644 index 0000000..9a0c9e5 --- /dev/null +++ b/day14/day14/Problem.cs @@ -0,0 +1,277 @@ +namespace day14; +public class Problem +{ + public string Result1 { get; set; } + public string Result2 { get; set; } + + private HashSet obstacles = new HashSet(); + private HashSet allDrops = new HashSet(); + + public void ResolvePart1(string arg) + { + var lines = File.ReadAllLines(arg); + + obstacles.Clear(); + allDrops.Clear(); + + //reading rocks + var bedrockLevel = 0; + foreach (var line in lines) + { + var linecoords = line.Split("->", + StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + Point prevCoord = null; + for (int i = 0; i < linecoords.Length; i++) + { + var currCoordStr = linecoords[i]; + var currCoords = currCoordStr.Split(","); + var currCoord = new Point(int.Parse(currCoords[0]), int.Parse(currCoords[1])); + //bedrock + bedrockLevel = Math.Max(bedrockLevel, currCoord.Y); + if (prevCoord != null) + { + //build rock + if (prevCoord.X == currCoord.X) + { + //same X axis + var min = Math.Min(prevCoord.Y, currCoord.Y); + var max = Math.Max(prevCoord.Y, currCoord.Y); + for (int j = min; j <= max; j++) + { + obstacles.Add(new Point(prevCoord.X, j)); + } + } + else if (prevCoord.Y == currCoord.Y) + { + //same y axis + var min = Math.Min(prevCoord.X, currCoord.X); + var max = Math.Max(prevCoord.X, currCoord.X); + for (int j = min; j <= max; j++) + { + obstacles.Add(new Point(j, prevCoord.Y)); + } + } + else + { + throw new ArgumentException("invalid coordinates"); + } + } + prevCoord = currCoord; + } + } + // ShowMap(obstacles, bedrockLevel); + + // START FALLING + var nrDrops = 0; + var fallInVoid = false; + while (!fallInVoid) + { + var isSettle = false; + var drop = new Point(500, 0); + nrDrops++; + while (!isSettle) + { + if (drop.Y + 1 > bedrockLevel) + { + nrDrops--;// subtract this last drop that will fall in void + fallInVoid = true; + break; + } + + //bellow + var next = new Point(drop.X, drop.Y + 1); + var didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //mode left + next = new Point(drop.X - 1, drop.Y + 1); + didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //mode right + next = new Point(drop.X + 1, drop.Y + 1); + didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //become obstacle + obstacles.Add(drop); + allDrops.Add(drop); + isSettle = true; + } + } + // System.Console.WriteLine($"nrDrops: {nrDrops}"); + // ShowMap(obstacles, bedrockLevel); + + + Result1 = nrDrops.ToString(); + } + + private bool TryMove(Point next) + { + return !obstacles.Contains(next); + } + + private void ShowMap(HashSet obstacles, int depth) + { + for (int j = 0; j <= depth; j++) + { + System.Console.Write($"{j} "); + for (int i = 420; i < 550; i++) + { + var tP = new Point(i, j); + if (obstacles.Contains(tP)) + { + if (allDrops.Contains(tP)) + { + System.Console.Write("o"); + } + else + { + System.Console.Write("#"); + } + } + else + { + System.Console.Write("."); + } + } + System.Console.WriteLine(); + } + } + + public void ResolvePart2(string arg) + { + var lines = File.ReadAllLines(arg); + + obstacles.Clear(); + allDrops.Clear(); + + //reading rocks + var bedrockLevel = 0; + foreach (var line in lines) + { + var linecoords = line.Split("->", + StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + Point prevCoord = null; + for (int i = 0; i < linecoords.Length; i++) + { + var currCoordStr = linecoords[i]; + var currCoords = currCoordStr.Split(","); + var currCoord = new Point(int.Parse(currCoords[0]), int.Parse(currCoords[1])); + //bedrock + bedrockLevel = Math.Max(bedrockLevel, currCoord.Y); + if (prevCoord != null) + { + //build rock + if (prevCoord.X == currCoord.X) + { + //same X axis + var min = Math.Min(prevCoord.Y, currCoord.Y); + var max = Math.Max(prevCoord.Y, currCoord.Y); + for (int j = min; j <= max; j++) + { + obstacles.Add(new Point(prevCoord.X, j)); + } + } + else if (prevCoord.Y == currCoord.Y) + { + //same y axis + var min = Math.Min(prevCoord.X, currCoord.X); + var max = Math.Max(prevCoord.X, currCoord.X); + for (int j = min; j <= max; j++) + { + obstacles.Add(new Point(j, prevCoord.Y)); + } + } + else + { + throw new ArgumentException("invalid coordinates"); + } + } + prevCoord = currCoord; + } + } + bedrockLevel += 2; + + for (int i = 0; i < 1200; i++) + { + obstacles.Add(new Point(i, bedrockLevel)); + } + // ShowMap(obstacles, bedrockLevel); + + // START FALLING + var nrDrops = 0; + var fallInVoid = false; + while (!fallInVoid) + { + var isSettle = false; + var drop = new Point(500, 0); + nrDrops++; + while (!isSettle) + { + if (drop.Y + 1 > bedrockLevel - 1) + { + obstacles.Add(drop); + allDrops.Add(drop); + isSettle = true; + // nrDrops--;// subtract this last drop that will fall in void + // fallInVoid = true; + break; + } + + //bellow + var next = new Point(drop.X, drop.Y + 1); + var didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //mode left + next = new Point(drop.X - 1, drop.Y + 1); + didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //mode right + next = new Point(drop.X + 1, drop.Y + 1); + didMove = TryMove(next); + if (didMove) + { + drop = next; + continue; + } + //become obstacle + if (obstacles.Contains(drop)) + { + nrDrops--;// subtract this last drop that will fall in void + fallInVoid = true; + break; + } + else + { + obstacles.Add(drop); + allDrops.Add(drop); + isSettle = true; + } + } + } + // System.Console.WriteLine($"nrDrops: {nrDrops}"); + + // ShowMap(obstacles, bedrockLevel); + + + Result2 = nrDrops.ToString(); + } +} diff --git a/day14/day14/Program.cs b/day14/day14/Program.cs new file mode 100644 index 0000000..f79d32f --- /dev/null +++ b/day14/day14/Program.cs @@ -0,0 +1,19 @@ +namespace day14; +class Program +{ + static void Main(string[] args) + { + var inputFile = "input.txt"; + // var inputFile = "testdata.txt"; + + var problem = new Problem(); + + problem.ResolvePart1(inputFile); + System.Console.WriteLine($"Result1: {problem.Result1}"); + //614 + + problem.ResolvePart2(inputFile); + System.Console.WriteLine($"Result2: {problem.Result2}"); + //26170 + } +} diff --git a/day14/day14/day14.csproj b/day14/day14/day14.csproj new file mode 100644 index 0000000..40c60dd --- /dev/null +++ b/day14/day14/day14.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/day14/day14/input.txt b/day14/day14/input.txt new file mode 100644 index 0000000..f328d05 --- /dev/null +++ b/day14/day14/input.txt @@ -0,0 +1,151 @@ +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +520,82 -> 524,82 +496,164 -> 500,164 +505,162 -> 509,162 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +526,94 -> 530,94 +513,116 -> 517,116 +493,162 -> 497,162 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +539,66 -> 544,66 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +517,85 -> 521,85 +523,85 -> 527,85 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +499,158 -> 503,158 +502,160 -> 506,160 +508,164 -> 512,164 +526,88 -> 530,88 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +518,66 -> 523,66 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +502,164 -> 506,164 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +524,60 -> 529,60 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +510,113 -> 514,113 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +514,94 -> 518,94 +511,91 -> 515,91 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +490,164 -> 494,164 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +523,91 -> 527,91 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +520,57 -> 525,57 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +511,145 -> 511,146 -> 517,146 -> 517,145 +521,63 -> 526,63 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +503,39 -> 514,39 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +517,60 -> 522,60 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +528,63 -> 533,63 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +494,133 -> 503,133 -> 503,132 +531,60 -> 536,60 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +523,54 -> 528,54 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +517,91 -> 521,91 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +514,63 -> 519,63 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +511,79 -> 511,77 -> 511,79 -> 513,79 -> 513,70 -> 513,79 -> 515,79 -> 515,73 -> 515,79 -> 517,79 -> 517,77 -> 517,79 -> 519,79 -> 519,77 -> 519,79 -> 521,79 -> 521,76 -> 521,79 +504,113 -> 508,113 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +501,116 -> 505,116 +511,145 -> 511,146 -> 517,146 -> 517,145 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +532,94 -> 536,94 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +499,162 -> 503,162 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +520,94 -> 524,94 +491,119 -> 491,120 -> 503,120 -> 503,119 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +491,119 -> 491,120 -> 503,120 -> 503,119 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +529,91 -> 533,91 +507,110 -> 511,110 +494,133 -> 503,133 -> 503,132 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +511,145 -> 511,146 -> 517,146 -> 517,145 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +491,119 -> 491,120 -> 503,120 -> 503,119 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +496,160 -> 500,160 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +527,57 -> 532,57 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +508,94 -> 512,94 +532,66 -> 537,66 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +494,23 -> 494,17 -> 494,23 -> 496,23 -> 496,20 -> 496,23 -> 498,23 -> 498,16 -> 498,23 -> 500,23 -> 500,18 -> 500,23 -> 502,23 -> 502,19 -> 502,23 -> 504,23 -> 504,18 -> 504,23 +520,88 -> 524,88 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +514,88 -> 518,88 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +504,107 -> 504,99 -> 504,107 -> 506,107 -> 506,97 -> 506,107 -> 508,107 -> 508,103 -> 508,107 +525,66 -> 530,66 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +535,63 -> 540,63 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +511,66 -> 516,66 +491,136 -> 491,138 -> 483,138 -> 483,141 -> 499,141 -> 499,138 -> 496,138 -> 496,136 +505,123 -> 505,125 -> 501,125 -> 501,130 -> 511,130 -> 511,125 -> 508,125 -> 508,123 +514,42 -> 514,46 -> 508,46 -> 508,51 -> 525,51 -> 525,46 -> 517,46 -> 517,42 +507,116 -> 511,116 +496,36 -> 496,34 -> 496,36 -> 498,36 -> 498,30 -> 498,36 -> 500,36 -> 500,31 -> 500,36 -> 502,36 -> 502,27 -> 502,36 -> 504,36 -> 504,29 -> 504,36 -> 506,36 -> 506,34 -> 506,36 -> 508,36 -> 508,34 -> 508,36 -> 510,36 -> 510,30 -> 510,36 -> 512,36 -> 512,30 -> 512,36 +507,149 -> 507,151 -> 502,151 -> 502,155 -> 516,155 -> 516,151 -> 511,151 -> 511,149 \ No newline at end of file diff --git a/day14/day14/testdata.txt b/day14/day14/testdata.txt new file mode 100644 index 0000000..1926028 --- /dev/null +++ b/day14/day14/testdata.txt @@ -0,0 +1,2 @@ +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 \ No newline at end of file diff --git a/day14/problem.md b/day14/problem.md new file mode 100644 index 0000000..6832852 --- /dev/null +++ b/day14/problem.md @@ -0,0 +1,120 @@ +--- Day 14: Regolith Reservoir --- +The distress signal leads you to a giant waterfall! Actually, hang on - the signal seems like it's coming from the waterfall itself, and that doesn't make any sense. However, you do notice a little path that leads behind the waterfall. + +Correction: the distress signal leads you behind a giant waterfall! There seems to be a large cave system here, and the signal definitely leads further inside. + +As you begin to make your way deeper underground, you feel the ground rumble for a moment. Sand begins pouring into the cave! If you don't quickly figure out where the sand is going, you could quickly become trapped! + +Fortunately, your familiarity with analyzing the path of falling material will come in handy here. You scan a two-dimensional vertical slice of the cave above you (your puzzle input) and discover that it is mostly air with structures made of rock. + +Your scan traces the path of each solid rock structure and reports the x,y coordinates that form the shape of the path, where x represents distance to the right and y represents distance down. Each path appears as a single line of text in your scan. After the first point of each path, each point indicates the end of a straight horizontal or vertical line to be drawn from the previous point. For example: + +498,4 -> 498,6 -> 496,6 +503,4 -> 502,4 -> 502,9 -> 494,9 +This scan means that there are two paths of rock; the first path consists of two straight lines, and the second path consists of three straight lines. (Specifically, the first path consists of a line of rock from 498,4 through 498,6 and another line of rock from 498,6 through 496,6.) + +The sand is pouring into the cave from point 500,0. + +Drawing rock as #, air as ., and the source of the sand as +, this becomes: + + + 4 5 5 + 9 0 0 + 4 0 3 +0 ......+... +1 .......... +2 .......... +3 .......... +4 ....#...## +5 ....#...#. +6 ..###...#. +7 ........#. +8 ........#. +9 #########. +Sand is produced one unit at a time, and the next unit of sand is not produced until the previous unit of sand comes to rest. A unit of sand is large enough to fill one tile of air in your scan. + +A unit of sand always falls down one step if possible. If the tile immediately below is blocked (by rock or sand), the unit of sand attempts to instead move diagonally one step down and to the left. If that tile is blocked, the unit of sand attempts to instead move diagonally one step down and to the right. Sand keeps moving as long as it is able to do so, at each step trying to move down, then down-left, then down-right. If all three possible destinations are blocked, the unit of sand comes to rest and no longer moves, at which point the next unit of sand is created back at the source. + +So, drawing sand that has come to rest as o, the first unit of sand simply falls straight down and then stops: + +......+... +.......... +.......... +.......... +....#...## +....#...#. +..###...#. +........#. +......o.#. +#########. +The second unit of sand then falls straight down, lands on the first one, and then comes to rest to its left: + +......+... +.......... +.......... +.......... +....#...## +....#...#. +..###...#. +........#. +.....oo.#. +#########. +After a total of five units of sand have come to rest, they form this pattern: + +......+... +.......... +.......... +.......... +....#...## +....#...#. +..###...#. +......o.#. +....oooo#. +#########. +After a total of 22 units of sand: + +......+... +.......... +......o... +.....ooo.. +....#ooo## +....#ooo#. +..###ooo#. +....oooo#. +...ooooo#. +#########. +Finally, only two more units of sand can possibly come to rest: + +......+... +.......... +......o... +.....ooo.. +....#ooo## +...o#ooo#. +..###ooo#. +....oooo#. +.o.ooooo#. +#########. +Once all 24 units of sand shown above have come to rest, all further sand flows out the bottom, falling into the endless void. Just for fun, the path any new sand takes before falling forever is shown here with ~: + +.......+... +.......~... +......~o... +.....~ooo.. +....~#ooo## +...~o#ooo#. +..~###ooo#. +..~..oooo#. +.~o.ooooo#. +~#########. +~.......... +~.......... +~.......... +Using your scan, simulate the falling sand. How many units of sand come to rest before sand starts flowing into the abyss below? + +To begin, get your puzzle input. + +Answer: + + +You can also [Share] this puzzle. \ No newline at end of file