From 8941f621840f756c1c7dabfedb27f7452c7360e1 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 4 Dec 2022 19:26:47 +0900 Subject: [aoc/2022] Finish day 4 --- aoc/2022/04/part-one.jl | 8 ++++++++ aoc/2022/04/part-two.jl | 8 ++++++++ 2 files changed, 16 insertions(+) create mode 100755 aoc/2022/04/part-one.jl create mode 100755 aoc/2022/04/part-two.jl (limited to 'aoc') 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)))) -- cgit 1.4.1