Created
December 18, 2016 21:20
-
-
Save theburningmonk/699ee72cbcabd21060429efaf9a1b492 to your computer and use it in GitHub Desktop.
Advent of Code (Day 18)
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 previousTiles (row : string) = | |
seq { | |
yield [| '.'; row.[0]; row.[1] |] | |
yield! row |> Seq.windowed 3 | |
yield [| row.[row.Length-2]; row.[row.Length-1]; '.' |] | |
} | |
let genRows input = | |
let nextRow = function | |
| [| '^'; '^'; '.' |] | |
| [| '^'; '.'; '.' |] | |
| [| '.'; '^'; '^' |] | |
| [| '.'; '.'; '^' |] -> '^' | |
| _ -> '.' | |
seq { | |
yield input | |
yield! input |> Seq.unfold (fun row -> | |
let nextRow = | |
row | |
|> previousTiles | |
|> Seq.map nextRow | |
|> Seq.toArray | |
|> fun chars -> new String(chars) | |
Some(nextRow, nextRow)) | |
} | |
let solve input n = | |
genRows input | |
|> Seq.take n | |
|> Seq.sumBy (fun row -> row |> Seq.filter ((=) '.') |> Seq.length) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment