-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday17_part01.fs
33 lines (25 loc) · 1.07 KB
/
day17_part01.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module day17_part01
open Intcode
open AdventOfCode_2019.Modules
open AdventOfCode_Utilities
let progOutputToGrid = List.map char >> charsToStr >> splitByFn "\n" (Array.map Seq.toArray)
let getGrid intcode =
match run (Computer.create intcode) with
| Output (output, _) -> progOutputToGrid output
| _ -> failwith "Expected an output"
let neighbours (x, y) = [| (x + 1, y); (x - 1, y); (x, y + 1); (x, y - 1) |]
let sumAligments (intcode) =
let g = getGrid intcode
let getAt (x, y) = Array.tryItem y g |> Option.bind (Array.tryItem x) |> Option.defaultValue '.'
let isScaffold (x, y) = getAt (x, y) = '#'
let isIntersection pos =
isScaffold pos && (neighbours pos |> Array.exists (isScaffold >> not) |> not)
seq {
for y = 1 to g.Length - 2 do
for x = 1 to g.[0].Length - 2 do
if isIntersection (x, y) then
x * y } |> Seq.sum
let execute =
let path = "day17/day17_input.txt"
let content = (LocalHelper.GetContentFromFile path).Split(",") |> Array.map int64
sumAligments content