From 5082e1a234045a0ed8aefb1dd7d1bef50540449c Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Mon, 5 Dec 2022 21:00:04 +1030 Subject: [PATCH] 2022 Day 4 Scala --- 2022/day4.scala | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2022/day4.scala diff --git a/2022/day4.scala b/2022/day4.scala new file mode 100644 index 0000000..d30c8cf --- /dev/null +++ b/2022/day4.scala @@ -0,0 +1,17 @@ +import scala.io.Source + +val numberPattern = raw"((?:(? numberPattern.findAllIn(line).map(_.toInt).toArray) + .map(n => ((n(0) to n(1)), (n(2) to n(3)))) + .toArray // Can't leave it lazy as Part 1 will consume it + + val subsets = rangePairs.map((a,b) => if (a.containsSlice(b) | b.containsSlice(a)) 1 else 0).sum + println(s"Part 1: $subsets elves have no unique work in their pairing") + + val overlaps = rangePairs.map((a,b) => if (a.intersect(b).isEmpty) 0 else 1).sum + println(s"Part 2: $overlaps elf pairs have overlapping work in their pairing")