aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-01-26 22:21:48 +0100
committerOscar Najera <hi@oscarnajera.com>2023-01-26 22:21:48 +0100
commit497dc1ea9de502761c00ead6de62abe6eeea67d6 (patch)
tree419167819228a8342b3dca08eb7964358b6c8845
parentc7f01066164817bbf624f2e7a63c6ac0aeea5f61 (diff)
downloadscratch-497dc1ea9de502761c00ead6de62abe6eeea67d6.tar.gz
scratch-497dc1ea9de502761c00ead6de62abe6eeea67d6.tar.bz2
scratch-497dc1ea9de502761c00ead6de62abe6eeea67d6.zip
more julia
-rw-r--r--AoC2022/04/solver.jl15
1 files changed, 15 insertions, 0 deletions
diff --git a/AoC2022/04/solver.jl b/AoC2022/04/solver.jl
new file mode 100644
index 0000000..0f512ae
--- /dev/null
+++ b/AoC2022/04/solver.jl
@@ -0,0 +1,15 @@
+
+using Test
+
+subinterval(a0, a1, b0, b1) = a0<= b0 && a1 >= b1
+subcontained(a0, a1, b0, b1) = subinterval(a0, a1, b0, b1) || subinterval(b0, b1, a0, a1)
+overlap(a0, a1, b0, b1) = a0 <= b1 && b0 <= a1
+
+data = open("input") do f
+ map(l-> parse.(Int, l), eachsplit.(eachsplit(read(f,String)), r"[,-]"))
+end
+
+@testset "solutions" begin
+ @test map(l-> subcontained(l...) ,data) |>sum == 515
+ @test map(l-> overlap(l...) ,data) |>sum == 883
+end