aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-27 23:15:58 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-27 23:15:58 +0100
commit4e6b4839f632cbd843da0f5fe39db00edc16f94c (patch)
tree4d3805a369cd945b56ae2b14dbea5e1a3c45ba62 /aoc-2022-dotnet
parent1d5b4ebc2683a4bc085fd0cfd23da524f32334d0 (diff)
downloadgleam_aoc2020-4e6b4839f632cbd843da0f5fe39db00edc16f94c.tar.gz
gleam_aoc2020-4e6b4839f632cbd843da0f5fe39db00edc16f94c.zip
Finish day 20
Diffstat (limited to 'aoc-2022-dotnet')
-rw-r--r--aoc-2022-dotnet/Day20/Day20.fsproj26
-rw-r--r--aoc-2022-dotnet/Day20/Program.fs47
-rw-r--r--aoc-2022-dotnet/README.md10
-rw-r--r--aoc-2022-dotnet/aoc-2022-dotnet.sln8
4 files changed, 85 insertions, 6 deletions
diff --git a/aoc-2022-dotnet/Day20/Day20.fsproj b/aoc-2022-dotnet/Day20/Day20.fsproj
new file mode 100644
index 0000000..795d59c
--- /dev/null
+++ b/aoc-2022-dotnet/Day20/Day20.fsproj
@@ -0,0 +1,26 @@
+<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>
+
+ <ItemGroup>
+ <PackageReference Include="FSharpPlus" Version="1.3.2" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\Common\Common.fsproj" />
+ </ItemGroup>
+
+</Project>
diff --git a/aoc-2022-dotnet/Day20/Program.fs b/aoc-2022-dotnet/Day20/Program.fs
new file mode 100644
index 0000000..9453a8d
--- /dev/null
+++ b/aoc-2022-dotnet/Day20/Program.fs
@@ -0,0 +1,47 @@
+module Day20
+
+open System.IO
+open FSharpPlus.Math.Generic
+open Common
+
+let mix listWithIds =
+ let cycle = List.length listWithIds - 1
+
+ let move xs idToMove =
+ let oldIndex = List.findIndex (fst >> (=) idToMove) xs
+ let element = xs[oldIndex]
+ let newIndex = int <| remE (int64 oldIndex + snd element) cycle
+
+ xs
+ |> List.removeAt oldIndex
+ |> List.insertAt newIndex element
+
+ seq { 0..cycle } |> Seq.fold move listWithIds
+
+let nthAfterZero n xs =
+ xs
+ |> List.item (remE (List.findIndex (snd >> (=) 0L) xs + n) (List.length xs))
+ |> snd
+
+let groveCoords multiplier rounds input =
+ let mixed =
+ input
+ |> Seq.map (int64 >> (*) multiplier)
+ |> Seq.indexed
+ |> List.ofSeq
+ |> Util.composition rounds mix
+
+ nthAfterZero 1000 mixed
+ + nthAfterZero 2000 mixed
+ + nthAfterZero 3000 mixed
+
+let solution1 = groveCoords 1 1
+let solution2 = groveCoords 811589153 10
+
+let test = File.ReadLines("test.txt")
+assert (solution1 test = 3)
+assert (solution2 test = 1623178306)
+
+let input = File.ReadLines("input.txt")
+printfn "%d" <| solution1 input
+printfn "%d" <| solution2 input
diff --git a/aoc-2022-dotnet/README.md b/aoc-2022-dotnet/README.md
index 8d6d1a8..bc6029a 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-36/50-orange)
+![Stars](https://img.shields.io/badge/🌟%20stars-38/50-orange)
| Day | Problem Name | Part 1 | Part 2 | Practiced Concepts |
| :----: | ---------------------------------------------------------------- | :----: | :----: | ---------------------------------------------------- |
@@ -23,9 +23,9 @@
| **17** | [Pyroclastic Flow](https://adventofcode.com/2022/day/17) | :star: | :star: | cycle detection, bitwise operators, hashing |
| **18** | [Boiling Boulders](https://adventofcode.com/2022/day/18) | :star: | :star: | functional DFS, 3D vectors, position bound checking |
| **19** | [Not Enough Minerals](https://adventofcode.com/2022/day/19) | | | |
-| **20** | [Grove Positioning System](https://adventofcode.com/2022/day/20) | | | |
+| **20** | [Grove Positioning System](https://adventofcode.com/2022/day/20) | :star: | :star: | linked lists, modulo & remainder |
| **21** | [Monkey Math](https://adventofcode.com/2022/day/21) | | | |
| **22** | [Monkey Map](https://adventofcode.com/2022/day/22) | | | |
-| **23** | ??? | | | |
-| **24** | ??? | | | |
-| **25** | ??? | | | |
+| **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) | | | |
diff --git a/aoc-2022-dotnet/aoc-2022-dotnet.sln b/aoc-2022-dotnet/aoc-2022-dotnet.sln
index 32a106b..61ce052 100644
--- a/aoc-2022-dotnet/aoc-2022-dotnet.sln
+++ b/aoc-2022-dotnet/aoc-2022-dotnet.sln
@@ -48,7 +48,9 @@ Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day16", "Day16\Day16.fsproj
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day17", "Day17\Day17.fsproj", "{7DEA7521-24E1-4ED4-9530-70E91731ADB3}"
EndProject
-Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day18", "Day18\Day18.fsproj", "{31BA1C7C-D4C3-4F57-8129-8EF280911878}"
+Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Day18", "Day18\Day18.fsproj", "{31BA1C7C-D4C3-4F57-8129-8EF280911878}"
+EndProject
+Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Day20", "Day20\Day20.fsproj", "{B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -136,6 +138,10 @@ Global
{31BA1C7C-D4C3-4F57-8129-8EF280911878}.Debug|Any CPU.Build.0 = Debug|Any CPU
{31BA1C7C-D4C3-4F57-8129-8EF280911878}.Release|Any CPU.ActiveCfg = Release|Any CPU
{31BA1C7C-D4C3-4F57-8129-8EF280911878}.Release|Any CPU.Build.0 = Release|Any CPU
+ {B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {B8263346-97C7-473B-B2EC-D7DC9D1DEF0F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE