Created
December 17, 2016 13:41
-
-
Save theburningmonk/fa5b45a3eb1a59876bd115ed4dfcaec4 to your computer and use it in GitHub Desktop.
Advent of Code (Day 16)
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
| let input = "11011110011011101" |> Seq.map ((=) '1') |> Seq.toArray | |
| let solve diskSize input = | |
| let rec dragonCurve (a : bool[]) = | |
| if a.Length >= diskSize | |
| then a.[0..diskSize-1] | |
| else | |
| [| | |
| yield! a | |
| yield false | |
| yield! a |> Seq.rev |> Seq.map (not) | |
| |] | |
| |> dragonCurve | |
| let rec calcCheckSum (input : bool[]) = | |
| let checkSum = | |
| input | |
| |> Seq.chunkBySize 2 | |
| |> Seq.map (fun [| x; y |] -> x = y) | |
| |> Seq.toArray | |
| if checkSum.Length % 2 = 0 then calcCheckSum checkSum else checkSum | |
| dragonCurve input |> calcCheckSum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment