summary refs log tree commit diff stats
path: root/day13.fsx
diff options
context:
space:
mode:
authorBrian Chu <brianmchu42@gmail.com>2022-02-18 15:11:04 -0800
committerBrian Chu <brianmchu42@gmail.com>2022-02-18 15:11:04 -0800
commit74ae7d8e8b05babdc8d3972827036fa6f0b2cade (patch)
tree0e875ee58d6fdf5a568e3f82bf58f590871680ab /day13.fsx
parentf3d54ee9e83324da6c2c8fc90ea2b5d5d749b0a5 (diff)
downloadAdventOfCode2017-74ae7d8e8b05babdc8d3972827036fa6f0b2cade.tar.gz
solutions up to day 14
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
ail.com> 2014-04-11 12:54:44 +0100 committer James Booth <boothj5@gmail.com> 2014-04-11 12:54:44 +0100 Added themes supplied by p41nm47r1x' href='/danisanti/profani-tty/commit/themes/spawn?id=6dabbbd54140fb161d2a03d6d3f4fe67585311c6'>6dabbbd5 ^
8a113ad6 ^
2f82f50a ^
86c1c388 ^
1a3dc91e ^
6dabbbd5 ^

30b5f112 ^
fbc30231 ^

















cd2458c0 ^

0ae975c2 ^

b21edfaa ^
cd2458c0 ^
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77