Skip to content

Instantly share code, notes, and snippets.

@manonthemat
Created December 9, 2022 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manonthemat/a6ff96a339788f8ecfe7c1bc2b6d1115 to your computer and use it in GitHub Desktop.
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
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