From 15f5a39ea1fbc91e63a1bb5575aeb032a82d795f Mon Sep 17 00:00:00 2001 From: scarf Date: Sat, 9 Nov 2024 18:12:16 +0900 Subject: [PATCH] feat: 2015 day 24 --- 2015/day24.scala | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 2015/day24.scala diff --git a/2015/day24.scala b/2015/day24.scala new file mode 100644 index 0000000..00b8bce --- /dev/null +++ b/2015/day24.scala @@ -0,0 +1,22 @@ +package `2015`.day24 + +import prelude.* + +def quantumEntanglement(xs: Iterable[Long]): Long = xs.product + +def solution(input: Vector[Long], group: Int) = + val groupWeight = input.sum / group + (1 to input.size).iterator + .map { n => input.combinations(n).filter(_.sum == groupWeight) } + .find(_.nonEmpty) + .get + .map(quantumEntanglement) + .min + +@main def main() = + val input = fromFile(".cache/2015/24.txt").getLines.map(_.toLong).toVector + + val part1 = solution(input, 3) + println(part1) + val part2 = solution(input, 4) + println(part2)