From d4577c74e8fbb1143050cb2880f08307eb953945 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Tue, 6 Dec 2022 12:17:31 +0100 Subject: Finish day 6 --- aoc-2022-dotnet/Day06/Program.fs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 aoc-2022-dotnet/Day06/Program.fs (limited to 'aoc-2022-dotnet/Day06/Program.fs') 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 -- cgit v1.2.3