Skip to content

Commit

Permalink
feat: 2015 day 24
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Nov 9, 2024
1 parent d63c931 commit 15f5a39
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 2015/day24.scala
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 15f5a39

Please sign in to comment.