aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day06/Program.fs
blob: 75a5ffba1b936d70b58f1ca5f45d8a8f78896f70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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