Skip to content

Instantly share code, notes, and snippets.

@theburningmonk
Created December 18, 2016 21:20
Show Gist options
  • Save theburningmonk/699ee72cbcabd21060429efaf9a1b492 to your computer and use it in GitHub Desktop.
Save theburningmonk/699ee72cbcabd21060429efaf9a1b492 to your computer and use it in GitHub Desktop.
Advent of Code (Day 18)
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