about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xaoc/2022/04/part-one.jl8
-rwxr-xr-xaoc/2022/04/part-two.jl8
2 files changed, 16 insertions, 0 deletions
diff --git a/aoc/2022/04/part-one.jl b/aoc/2022/04/part-one.jl
new file mode 100755
index 0000000..3f409ea
--- /dev/null
+++ b/aoc/2022/04/part-one.jl
@@ -0,0 +1,8 @@
+#!/usr/bin/env julia
+function containing(line)
+  (a, b), (c, d) = map(r -> map(i -> parse(Int16, i),
+                                split(r, '-')),
+                       split(line, ','))
+  (c - a) * (d - b) <= 0
+end
+println(sum(map(containing, readlines(stdin))))
diff --git a/aoc/2022/04/part-two.jl b/aoc/2022/04/part-two.jl
new file mode 100755
index 0000000..9f4dbaf
--- /dev/null
+++ b/aoc/2022/04/part-two.jl
@@ -0,0 +1,8 @@
+#!/usr/bin/env julia
+function overlapping(line)
+  (a, b), (c, d) = map(r -> map(i -> parse(Int16, i),
+                                split(r, '-')),
+                       split(line, ','))
+  !(b < c || d < a)
+end
+println(sum(map(overlapping, readlines(stdin))))