Created
December 6, 2022 10:47
-
-
Save Descalon/096394e92bfcd83b29a63bfd26d95328 to your computer and use it in GitHub Desktop.
Day 6
This file contains hidden or 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 private readFile input = | |
System.IO.File.ReadAllLines(input) |> List.ofArray | |
let markerData () = "datafiles/marker.txt" |> readFile |> List.head |
This file contains hidden or 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
#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