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")