summary refs log tree commit diff stats
path: root/day13.fsx
diff options
context:
space:
mode:
Diffstat (limited to 'day13.fsx')
-rw-r--r--day13.fsx17
1 files changed, 17 insertions, 0 deletions
diff --git a/day13.fsx b/day13.fsx
new file mode 100644
index 0000000..b7c9975
--- /dev/null
+++ b/day13.fsx
@@ -0,0 +1,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"
\ No newline at end of file