aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--aoc-2022-dotnet/Day25/Day25.fsproj18
-rw-r--r--aoc-2022-dotnet/Day25/Program.fs39
-rw-r--r--aoc-2022-dotnet/README.md4
-rw-r--r--aoc-2022-dotnet/aoc-2022-dotnet.sln8
5 files changed, 67 insertions, 4 deletions
diff --git a/README.md b/README.md
index 583fa7e..608545e 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ Repository storing my solutions to Advent of Code. See other people's solutions
### [2022](aoc-2022-dotnet)
![F#](https://img.shields.io/badge/F%23-grey?logo=.NET)
-![Stars](https://img.shields.io/badge/🌟%20stars-40/50-orange)
+![Stars](https://img.shields.io/badge/🌟%20stars-41/50-orange)
[awesome]: https://github.com/Bogdanp/awesome-advent-of-code
[aoc]: https://adventofcode.com
diff --git a/aoc-2022-dotnet/Day25/Day25.fsproj b/aoc-2022-dotnet/Day25/Day25.fsproj
new file mode 100644
index 0000000..e337a41
--- /dev/null
+++ b/aoc-2022-dotnet/Day25/Day25.fsproj
@@ -0,0 +1,18 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Include="test.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Content Include="input.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+
+</Project>
diff --git a/aoc-2022-dotnet/Day25/Program.fs b/aoc-2022-dotnet/Day25/Program.fs
new file mode 100644
index 0000000..c4e1878
--- /dev/null
+++ b/aoc-2022-dotnet/Day25/Program.fs
@@ -0,0 +1,39 @@
+module Day25
+
+open System
+open System.IO
+
+module Number =
+ module private Digit =
+ let private values =
+ [ ('=', -2L)
+ ('-', -1L)
+ ('0', 0L)
+ ('1', 1L)
+ ('2', 2L) ]
+
+ let snafuTuLong c = List.find (fst >> (=) c) values |> snd
+ let longToSnafu d = List.find (snd >> (=) d) values |> fst
+
+ let snafuToLong =
+ let rec helper =
+ function
+ | [] -> 0L
+ | digit :: rest -> Digit.snafuTuLong digit + 5L * helper rest
+
+ Seq.rev >> List.ofSeq >> helper
+
+ let rec longToSnafu =
+ function
+ | 0L -> ""
+ | digit ->
+ let (div, rem) = Math.DivRem(digit + 2L, 5L)
+ sprintf "%s%c" (longToSnafu div) (Digit.longToSnafu <| rem - 2L)
+
+let solution = Seq.sumBy Number.snafuToLong >> Number.longToSnafu
+
+let test = File.ReadLines("test.txt")
+assert (solution test = "2=-1=0")
+
+let input = File.ReadLines("input.txt")
+printfn "%s" <| solution input
diff --git a/aoc-2022-dotnet/README.md b/aoc-2022-dotnet/README.md
index 37de967..97d275f 100644
--- a/aoc-2022-dotnet/README.md
+++ b/aoc-2022-dotnet/README.md
@@ -1,6 +1,6 @@
# Advent of Code 2022 in F#
![F#](https://img.shields.io/badge/F%23-grey?logo=.NET)
-![Stars](https://img.shields.io/badge/🌟%20stars-40/50-orange)
+![Stars](https://img.shields.io/badge/🌟%20stars-41/50-orange)
| Day | Problem Name | Part 1 | Part 2 | Practiced Concepts |
| :----: | ---------------------------------------------------------------- | :----: | :----: | ---------------------------------------------------- |
@@ -28,4 +28,4 @@
| **22** | [Monkey Map](https://adventofcode.com/2022/day/22) | | | |
| **23** | [Unstable Diffusion](https://adventofcode.com/2022/day/23) | | | |
| **24** | [Blizzard Basin](https://adventofcode.com/2022/day/24) | | | |
-| **25** | [Full of Hot Air](https://adventofcode.com/2022/day/25) | | | |
+| **25** | [Full of Hot Air](https://adventofcode.com/2022/day/25) | :star: | | positional numeral systems, recursion |
diff --git a/aoc-2022-dotnet/aoc-2022-dotnet.sln b/aoc-2022-dotnet/aoc-2022-dotnet.sln
index 0de2b21..9cfa122 100644
--- a/aoc-2022-dotnet/aoc-2022-dotnet.sln
+++ b/aoc-2022-dotnet/aoc-2022-dotnet.sln
@@ -52,7 +52,9 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day18", "Day18\Day18.fsproj
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day20", "Day20\Day20.fsproj", "{B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}"
EndProject
-Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day21", "Day21\Day21.fsproj", "{7168DBF8-A03D-43A5-A429-FBAF87D55FF6}"
+Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day21", "Day21\Day21.fsproj", "{7168DBF8-A03D-43A5-A429-FBAF87D55FF6}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day25", "Day25\Day25.fsproj", "{3CBC73E3-821C-45FC-85F8-877C29810E67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -148,6 +150,10 @@ Global
{7168DBF8-A03D-43A5-A429-FBAF87D55FF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7168DBF8-A03D-43A5-A429-FBAF87D55FF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7168DBF8-A03D-43A5-A429-FBAF87D55FF6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {3CBC73E3-821C-45FC-85F8-877C29810E67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {3CBC73E3-821C-45FC-85F8-877C29810E67}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {3CBC73E3-821C-45FC-85F8-877C29810E67}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {3CBC73E3-821C-45FC-85F8-877C29810E67}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE