Tuning Trouble

Description: https://adventofcode.com/2022/day/6

open System.IO
open System

type Input() =
    let mutable counter = 0

    let isDistinctFour (lastFour: char[]) (distinctCount: int) : bool =
        (Array.distinct lastFour |> Array.length) = distinctCount

    member _.Compute(part: int) =
        use stream = new StreamReader "./input.txt"

        let markerLen = if part = 1 then 4 else 14
        let mutable lastN = Array.create markerLen ' '

        let mutable foundIndex = false
        let mutable c = stream.Read()

        while (c <> -1 && not foundIndex) do
            let next = c |> char

            counter <- counter + 1
            lastN <- (Array.append lastN[1..] [| next |])

            if isDistinctFour lastN markerLen then
                foundIndex <- true

            c <- stream.Read()

        counter

let input = Input()
let part = (Environment.GetCommandLineArgs()[1]) |> int

printfn "%d" (input.Compute(part))