init current

This commit is contained in:
Claudiu Farcas
2022-12-14 20:34:09 +02:00
commit cb1aeea711
150 changed files with 19361 additions and 0 deletions
+398
View File
@@ -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
+26
View File
@@ -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"
}
]
}
+5
View File
@@ -0,0 +1,5 @@
{
"cSpell.enableFiletypes": [
"!plaintext"
]
}
+41
View File
@@ -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"
}
]
}
+4
View File
@@ -0,0 +1,4 @@
# Advent of code 2022
My C# solutions for
<https://adventofcode.com/>
+242
View File
@@ -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
+24
View File
@@ -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
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day01/day01.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
File diff suppressed because it is too large Load Diff
+26
View File
@@ -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"
}
]
}
+41
View File
@@ -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"
}
]
}
+7
View File
@@ -0,0 +1,7 @@
namespace day01;
public class Elf
{
public int Index { get; set; }
public int Calories { get; set; }
}
+73
View File
@@ -0,0 +1,73 @@
namespace day01;
public class Problem
{
List<Elf> lst = new List<Elf>();
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();
}
}
+13
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
File diff suppressed because it is too large Load Diff
+58
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day02/day02.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+3
View File
@@ -0,0 +1,3 @@
A Y
B X
C Z
+82
View File
@@ -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
};
}
}
+8
View File
@@ -0,0 +1,8 @@
namespace day02;
public enum GameScore
{
Win,
Loss,
Draw
}
+8
View File
@@ -0,0 +1,8 @@
namespace day02;
public enum GameSymbols
{
Rock = 1,
Paper = 2,
Scissor = 3
}
+63
View File
@@ -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;
}
}
+44
View File
@@ -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
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
File diff suppressed because it is too large Load Diff
+50
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day03/day03.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+6
View File
@@ -0,0 +1,6 @@
vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
+68
View File
@@ -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;
}
}
+15
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+300
View File
@@ -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
HwQwwbwFNWHwHBVFQFLQzRznZnSzcjjj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StmHJsJsLZLjTvM
QssMbVGdMQjZPjwVwHVZPZClllvgSgvlTgwwSSCgSCtC
WmmFBmJrcFRBFrJJBFchzWCStgCTgvhvTlfsNqfTlvTv
sFzzssDLzrBPjDVVddHMQD
fztDZSGrNrlnbnPTgFFpln
jvvQMMcLcjJmQwHdJvjQJnnbTbRFRphnnpsWgmFRPR
vTLHHCQLHBBjJCSZrVCZtSfSfrft
gHfHffHLjwHrRjLrLRZVMnTdTBsNTBwTVBsBnN
DWPhqhhDhvSGvWPzSzMBQBQVMMBBmvssvQvQ
CDGbqCDbChSbWGrHcHRgbcVcfrLJ
frlTLmtllbbbdpJS
qFjhzjThjHTFGHTjqhhjMzBhVpVpdbBnSJQRpBnVVdbRRQJd
vjWPWjWPPPWgwmfCrNvTvZ
+67
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day04/day04.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+6
View File
@@ -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
+50
View File
@@ -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);
}
}
+15
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
File diff suppressed because it is too large Load Diff
+65
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day05/day05.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+9
View File
@@ -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
+140
View File
@@ -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<Stack<string>> listOfStacks = new List<Stack<string>>();
for (int j = 0; j < noStacks; j++)
{
listOfStacks.Add(new Stack<string>());
}
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 (?<pieces>[0-9]+) from (?<from>[0-9]+) to (?<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<string>();
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<Stack<string>> listOfStacks = new List<Stack<string>>();
for (int j = 0; j < noStacks; j++)
{
listOfStacks.Add(new Stack<string>());
}
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 (?<pieces>[0-9]+) from (?<from>[0-9]+) to (?<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<string>();
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();
}
}
+16
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+512
View File
@@ -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
+9
View File
@@ -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
+106
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day06/day06.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+5
View File
@@ -0,0 +1,5 @@
mjqjpqmgbljsphdztnvjfqwrcgsmlb
bvwbjplbgvbhsrlpgdmjqwftvncz
nppdvjthqldpwncqszvftbrmjlhg
nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg
zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw
+62
View File
@@ -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<int> lstIdx = new List<int>();
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<int> lstIdx = new List<int>();
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);
}
}
+16
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+1
View File
@@ -0,0 +1 @@
rhghwwsmsgmgsmmmlzljllrddvsvhvhhnvvrcccwhhvgghchwhvwvcvrrrgtgrgdggfdgffshsllvvslsppglgvgwgswwcbcwbwrrbjbwjjtgjjdzdfdhfddrmmhqhpqhhqghhzssqzqccbwwffzvzffvtftddrbrtrrcjrrmmbmrrrlrppplmplmppfzpfpvpqvpqqdndpndnmnwmwjmwmwbbrhhmzmffwfqwfqwffppvfpvffnwwwwcbwbhbccvmmplmplmmlmplpprbpbllmhlhzhffngfnntrrsrprrvlllvjvmjvvppsrrfnrfnrfrfwrffrsfrflfltfllpfprrthhhnhqnnfwwcttvzzddqsddwpddnrnttvjttjjdjvdjvjnvnrvvchhschhlffjggtqgqnnvrnrsnrsnsvspsnncppvwvvtmmcqmcmscmsmwmvmpvvlqqmbqqlwwtgtztgttpjjbfjjzhzthhzssffwqqdmdcdlclrclrccbmmqjqmqcmmnnsvnntpphhdpdhhtbtdtffhzfhhpwhppwbppfspphdhggzqgzzffdsdfsszcscpscsqcssffhjhnhhlqqdbqqdmdsmddrfddndldgglvglvlggqlggjngjnnbffthhjbjpjnjmnmgmqqbjqjzjqzzzjffwttcnnzffmllcncmnnthnncttpgpnnjdjfftmmvqmqsqggfrfjjqbjbvvshvhphfhhljlfjjvcclzclctcmmfwfvwfvwwjvwvjjplpbpqqdvqqbhbdbnnsndssgffgsglssmfmjjfrjfrfttljldjdffjjdnjjlbbnrntrtfrttmhhndnsdsffgqqrpplvvfwvfvsfszzfzhfzzlttlctllrzrggvwvhhgnnlmnlmlpppdldqqdpdlplrpppjspspzzhphccgjjpmmwvwbwssnpssrzrwrhhmzhmhsmhmttrqrvqvcclggptpjpzpccltctppflfjffrtrjrhjhffhjfjbfjfqfqzffdtthwwjwzjzggsgzgqqjdqjddvgvsvnnqwqgwgtttfvfrfwrfwfwmwmqwmmmbzmzvzfvfrfvvgvtvptpbpwbwrbwrwffzzfgzfgfcfzcffjdjjvrvnnfmmtztffsggjcjzcjcssscnscnssmmwgwbbljlnjndnrrqwqjjjbnnmbmcmbcmbbvvmtvmmfcmcjcdcnnzfzfzqfzfvvmbvmmndnbnsnnlddqvvsnngvnnrttfbtbqqnwqqzfzfzccfmmgrrsbbhvvgjjhfhssjmmsjjzzbqblqlfqllwhlwwvvstvtfvttnncjjzcjcjrrsvrssmfsfczbrzrvscvmcmrjpzwhcqfrrzbljnmqlzbzqtmhrshlrjjpvhnsvtlhqggqwppsjpszmqwfqmlwbqzwcrggrvfbvztnflwvbrqcrqbcllswvsvhwjzpldgphwptfdnlgdlnbttjfzrdcfvpdhlssfsljvdjmwddbnrpqnnqlfdfdspbnjwqjwrgtnrftsqcfjpmqwgwhttggjwzvgbwlhmtmmjlwhssrgshzpbcnstzlqdshdhjfgqlsmqqhpwbscsjhfbhprvhmftqngjgdbcvfldqgqsjqjfdmcvsflwzflsjfssnjpbwffnsfcnrdsphbjpgghmcthgnzmpgppqjdvbztvhnwqzndntcpjdtwwhvsmgdcthpssszrqcbntgsznpghmbqddpqscntjprlwzhbzhjtwzbwwcldwdgsttzmtnstjnngzrgvhncdbgqnllfzbthldztsdwsngjzprbvrnbzrsghlgssbqfnbvhnhzwmmmtncvsdngdtwcbjlnnzbnlrnmrvnvsjnvzdqnggmsvljlvjznwdszcmblhrsjvczpnlhsmqjsmwhbjbplbtqsgqjdllhncwdgbvzwnmqvndcbfhnvtjnzmvjhwzvdldhgfwbqqzcnbflfnwntlhmqgdhmrgwqcpmsvfbmwhbtsbdlhcnbcbswvdfffgjvddrbpzpcwsrsjnfvmzhlvbdnwttnqrmzbnnntbfvptrlhjhwjcsbnhvtwtwzvgfnzjplthqjbsjjwzdtqqvblnbvgcmvrmnvmwfrhcqgvrcjlfzdlpbfvncbtfgvnsflbjzqqhczcmtbwqmrppmptfgzvfbmcslwlfrfpvvnvvnwfvvmmdzmmtjsgqdfhngtphtlfjqrtljgnthgnbbqfrnpfmpwhpzdvzmtswwdvcnpsdcqwjdwlvbsbmlwdsjbcbgcrfljshlvpngfmsrzlfhtfqgwbcctnzzhnqhdmqzdwthftwtmpbcmqvdcdtgvltbzmszzwwmhzlfvbdqnhjqgdmstsnhftcwzvvbmnhwvgqzscwcdjbdgfmvpjdzctwqwltbwjlgcblnnhpnmggbmvqpqtgqjzspgqzvcvsdbvjgjfzdzhfpbzjqljjcgldzgnlmtjcmfgdbqgglvjqrppwmhccvqzvsrjjvfhjprwdsqsnszfprznljtcsrtqhcrpljfrccflmbpvqtzgmzhjrlbnrmmsmmjbtzwpglqgdvvvjvnfzmplsmvlvcnjshvjwntclwgpznnzwhjssgdcjbzrmsgnfgcgphrhfvrfhzwdcvsplhbmqwhpmjvqlmschznbqblvhtqfgtdggmncndhhplnzjphccjmlmtdqnmnlnpnfqdstljqnsqbrjrtspvrwvdmwzlgdmsfvctzgtmgqhqqrzpbgplzcfdqnzhsqrbcvhsccshnnpvvrpvqzqsgzgmpzfvvrrcvhdtntnsqnjrbzlbzmpgwdqzbhtlrrhbwdqjlsfgdhmvgmgbqhwvljmmqfllqvvrznrlftgzjdcgtstjffqmgvffpvtctzpdqjfnmlcdzscntctmqhrtmhrlhbjzttrcvcnlhsrvtpbmdchhntnnpnzlvqqnsrjcmblcvphqgwshnjmplgvnbsmmdzgqcpqztjhhgjvtlbpdpdwlwmmfrdgcvzfbgvbgpbjnwsssvhszwplcgvpgjwdrwngbcdjwvlsfhqlrqzgrzpfgjstqfdbrpqdvrlgdwqcsrgvhctznjjlzsmzctsqtfnhhlpjgnltssglmlwshfbrgmjqbvsmqwvszdfsvhmtrfjgwjctpsmgzzjbpwsztnnvzrhwvvmhdpgdmwzsjprhlgzcdvhznlfgjqvcwqrplcfvzmthsdsnrtfvnlrmvwplmbdvdggmlvpgdgzhvzmvzwmptzsnfrcrjspccmqjpjmhjqgrjbdcdjbzjmphmcdvjqtmdshhjrqgjgsnpzfbfgpjpczwzvmclgzgztlvzmdbwgncnndjwhhhjnhtjdmcnrmnqbmjdrdcmtvcsmftqcfhsvhsfjmtzjpnwffggpfqlqmzlbhnnhbtgzfgnjvdzmvthqjrhzbwvhcjzcsmsvsctrqbltpcrpjjnsbjdbfjqfcbpcgcwtqsflmlwprjcwlmcjjgsfdpwcqvhjpsgvdgsfnscnbzsrmrbbvdrlltzplbvgqsdnplcvbhddbtmwnfmvqhqdlrtrmrmzmhlccgwgmbdppjqdjtwmvdzfsbsggrfstjwjpjnljffwffmqncfnthnhglwvsgvzmgbzhtdfpfmdwmcldthvsnqnptpmhqctblgfsszhcfbvcrggjdhthqvvvlldshvqwmvdtfslrhzvgdfwztrczdjgcfcgtmwnphqthlgpfnrqwcgpzwnlgdvsnvzftlnlfflfsmjzhrhqjctsbvtccwbfsdrnbhszzjhqndvwcsmffnstnfdfwpbgfztjmjngdczzlgpscjtshpmmmzlnqndsttbdgfjqcvbqlphwhlhgcvjbhjmtrfzlgpwdnvzrllndbhvhlngvhlszzdcrdgvrmjwcvhhtbhnjmdzgctqnpdlrnqjzbchjtcsggsczlgmvtqvzmsqvtrhtvdmzlcdddfnbvbsnrzvgzfqjtbhjqhdznrhbfbqwtnwvrfqsznbqfzfzfgmhvjjsgbbdbdtzswwlnfrq
+55
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day07/day07.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+23
View File
@@ -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
+50
View File
@@ -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<string> lsResult)
{
lsResult = new List<string>();
while (++i < lines.Length && !lines[i].IsCommand())
{
lsResult.Add(lines[i]);
}
return cmd == "ls";
}
}
+44
View File
@@ -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<Node> 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}/";
}
}
}
}
+7
View File
@@ -0,0 +1,7 @@
namespace day07;
public enum NodeType
{
Directory,
File
}
+112
View File
@@ -0,0 +1,112 @@
namespace day07;
public class Problem
{
public string Result1 { get; set; }
public string Result2 { get; set; }
private List<Node> allFolders = new List<Node>();
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<string> 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();
}
}
+16
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
File diff suppressed because it is too large Load Diff
+103
View File
@@ -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.
+22
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day08/day08.csproj" />
<Content Include="testdata.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+5
View File
@@ -0,0 +1,5 @@
30373
25512
65332
33549
35390
+164
View File
@@ -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();
}
}
+16
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+99
View File
@@ -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
+75
View File
@@ -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.
+31
View File
@@ -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");
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;
+32
View File
@@ -0,0 +1,32 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../day09/day09.csproj" />
<Content Include="*.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
+8
View File
@@ -0,0 +1,8 @@
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2
+8
View File
@@ -0,0 +1,8 @@
R 5
U 8
L 8
D 3
R 17
D 10
L 25
U 20
+152
View File
@@ -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)
);
}
}
}
}
+16
View File
@@ -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}");
}
}
+10
View File
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
File diff suppressed because it is too large Load Diff
+683
View File
@@ -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.
+22
View File
@@ -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);
}
}
+1
View File
@@ -0,0 +1 @@
global using Xunit;

Some files were not shown because too many files have changed in this diff Show More