Created
December 9, 2022 02:06
-
-
Save manonthemat/a6ff96a339788f8ecfe7c1bc2b6d1115 to your computer and use it in GitHub Desktop.
Advent of Code 2022 - Day 06 in F# - I don't know anything
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
//let input = IO.File.ReadAllLines("sample.txt") |> Array.head | |
let input = IO.File.ReadAllLines("data.txt") |> Array.head | |
let indexOfFirstMarker (windowSize: int) (input: string) : int = | |
input.ToCharArray() | |
|> Array.windowed windowSize | |
|> Array.takeWhile (fun xs -> Array.distinct xs |> Array.length <> windowSize) | |
|> Array.length | |
|> (+) windowSize | |
let result1 = indexOfFirstMarker 4 input | |
printfn $"Result 1: {result1}" | |
let result2 = indexOfFirstMarker 14 input | |
printfn $"Result 2: {result2}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment