summary refs log tree commit diff stats
path: root/day13.fsx
blob: b7c99756243603b07411bbeac21c47de521e10b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
open System.IO

let isCaught offset pos =
    let time, length = pos
    (time + offset) % ((length - 1) * 2) = 0

let severity positions offset =
    Array.filter (isCaught offset) positions |> Array.map (fun (t, n) -> t * n) |> Array.sum

let notCaught positions offset =
    Array.filter (isCaught offset) positions |> Array.length |> (fun x -> x = 0)

let () =
    let scanners = File.ReadAllLines "day13.txt" |> Array.map (fun x -> x.Split(':')) |> Array.map (fun x -> int x[0], int x[1])
    
    severity scanners 0 |> printfn "%d"
    Seq.initInfinite id |> Seq.filter (notCaught scanners) |> Seq.head |> printfn "%d"