diff options
author | Brian Chu <brianmchu42@gmail.com> | 2022-02-18 15:11:04 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2022-02-18 15:11:04 -0800 |
commit | 74ae7d8e8b05babdc8d3972827036fa6f0b2cade (patch) | |
tree | 0e875ee58d6fdf5a568e3f82bf58f590871680ab /day13.fsx | |
parent | f3d54ee9e83324da6c2c8fc90ea2b5d5d749b0a5 (diff) | |
download | AdventOfCode2017-74ae7d8e8b05babdc8d3972827036fa6f0b2cade.tar.gz |
solutions up to day 14
Diffstat (limited to 'day13.fsx')
-rw-r--r-- | day13.fsx | 17 |
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 |