Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created December 17, 2016 13:41
Show Gist options
  • Select an option

  • Save theburningmonk/fa5b45a3eb1a59876bd115ed4dfcaec4 to your computer and use it in GitHub Desktop.

Select an option

Save theburningmonk/fa5b45a3eb1a59876bd115ed4dfcaec4 to your computer and use it in GitHub Desktop.
Advent of Code (Day 16)
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