about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-04 19:26:47 +0900
committerNguyễn Gia Phong <mcsinyx@disroot.org>2022-12-04 19:26:47 +0900
commit8941f621840f756c1c7dabfedb27f7452c7360e1 (patch)
tree13c316eb7d451874ef97aa279036084828a5d9d8
parenteeb9a45346a81ca417cf8dd9f88d3ca1ed88935a (diff)
downloadcp-8941f621840f756c1c7dabfedb27f7452c7360e1.tar.gz
[aoc/2022] Finish day 4
-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))))