aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day06
diff options
context:
space:
mode:
authorTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-06 12:17:31 +0100
committerTomasz Chojnacki <tomaszchojnacki2001@gmail.com>2022-12-06 12:17:31 +0100
commitd4577c74e8fbb1143050cb2880f08307eb953945 (patch)
tree9ab170b8bee6a1dc4afed0b2f603043e44ec648a /aoc-2022-dotnet/Day06
parentf0820f9561713bf6a14455d3b218f2144d8d43d0 (diff)
downloadgleam_aoc2020-d4577c74e8fbb1143050cb2880f08307eb953945.tar.gz
gleam_aoc2020-d4577c74e8fbb1143050cb2880f08307eb953945.zip
Finish day 6
Diffstat (limited to 'aoc-2022-dotnet/Day06')
-rw-r--r--aoc-2022-dotnet/Day06/Day06.fsproj15
-rw-r--r--aoc-2022-dotnet/Day06/Program.fs18
2 files changed, 33 insertions, 0 deletions
diff --git a/aoc-2022-dotnet/Day06/Day06.fsproj b/aoc-2022-dotnet/Day06/Day06.fsproj
new file mode 100644
index 0000000..249287d
--- /dev/null
+++ b/aoc-2022-dotnet/Day06/Day06.fsproj
@@ -0,0 +1,15 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net7.0</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Content Include="input.txt">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
+ <Compile Include="Program.fs" />
+ </ItemGroup>
+
+</Project>
diff --git a/aoc-2022-dotnet/Day06/Program.fs b/aoc-2022-dotnet/Day06/Program.fs
new file mode 100644
index 0000000..75a5ffb
--- /dev/null
+++ b/aoc-2022-dotnet/Day06/Program.fs
@@ -0,0 +1,18 @@
+open System.IO
+
+let solution n =
+ Seq.windowed n
+ >> Seq.findIndex (Set >> Set.count >> (=) n)
+ >> (+) n
+
+assert
+ [ ("mjqjpqmgbljsphdztnvjfqwrcgsmlb", 7, 19)
+ ("bvwbjplbgvbhsrlpgdmjqwftvncz", 5, 23)
+ ("nppdvjthqldpwncqszvftbrmjlhg", 6, 23)
+ ("nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg", 10, 29)
+ ("zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw", 11, 26) ]
+ |> List.forall (fun (test, s4, s14) -> solution 4 test = s4 && solution 14 test = s14)
+
+let input = File.ReadAllText "input.txt"
+printfn "%d" <| solution 4 input
+printfn "%d" <| solution 14 input