Skip to content

Instantly share code, notes, and snippets.

@Descalon
Created December 6, 2022 10:47
Show Gist options
  • Save Descalon/096394e92bfcd83b29a63bfd26d95328 to your computer and use it in GitHub Desktop.
Save Descalon/096394e92bfcd83b29a63bfd26d95328 to your computer and use it in GitHub Desktop.
Day 6
open System
let private readFile input =
System.IO.File.ReadAllLines(input) |> List.ofArray
let markerData () = "datafiles/marker.txt" |> readFile |> List.head
#load "Data.fsx"
#r "nuget:Expecto"
open System
open Expecto
let print p =
printfn "Result of day %i part %i = %O" 6 part result
let testdata =
[ "mjqjpqmgbljsphdztnvjfqwrcgsmlb"
"bvwbjplbgvbhsrlpgdmjqwftvncz"
"nppdvjthqldpwncqszvftbrmjlhg"
"nznrnfrfntjfmvfwmzdfjlvtqnbhcprsg"
"zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw" ]
let isUnique (xs: seq<'a>) =
xs |> Seq.distinct |> Seq.length |> (=) (Seq.length xs)
let pair a b = a,b
let findUniqueAfter n = Seq.windowed n >> Seq.mapi pair >> Seq.find (snd >> isUnique) >> fst >> (+) n
let findFirstMarker = findUniqueAfter 4
let testResult = testdata |> List.map findFirstMarker
let expectedResult = [7;5;6;10;11]
Expect.equal testResult expectedResult "Test result is incorrect"
Data.markerData () |> findFirstMarker |> print 1
let findMessage = findUniqueAfter 14
let testResult2 = testdata |> List.map findMessage
let expectedResult2 = [19;23;23;29;26]
Expect.equal testResult2 expectedResult2 "Test result is incorrect"
Data.markerData () |> findMessage |> print 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment