File tree Expand file tree Collapse file tree 4 files changed +43
-0
lines changed
resources/AdventOfCode2015
test/scala/AdventOfCode2015 Expand file tree Collapse file tree 4 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -226,3 +226,4 @@ The minimal SBT project provides:
226
226
| 14 | [ Reindeer Olympics] ( https://adventofcode.com/2015/day/14 ) | [ Source] ( src/main/scala/AdventOfCode2015/Day14.scala ) |
227
227
| 15 | [ Science for Hungry People] ( https://adventofcode.com/2015/day/15 ) | [ Source] ( src/main/scala/AdventOfCode2015/Day15.scala ) |
228
228
| 16 | [ Aunt Sue] ( https://adventofcode.com/2015/day/16 ) | [ Source] ( src/main/scala/AdventOfCode2015/Day16.scala ) |
229
+ | 17 | [ No Such Thing as Too Much] ( https://adventofcode.com/2015/day/17 ) | [ Source] ( src/main/scala/AdventOfCode2015/Day17.scala ) |
Original file line number Diff line number Diff line change
1
+ 11
2
+ 30
3
+ 47
4
+ 31
5
+ 32
6
+ 36
7
+ 3
8
+ 1
9
+ 5
10
+ 3
11
+ 32
12
+ 36
13
+ 15
14
+ 11
15
+ 46
16
+ 26
17
+ 28
18
+ 1
19
+ 19
20
+ 3
Original file line number Diff line number Diff line change
1
+ package AdventOfCode2015
2
+
3
+ object Day17 :
4
+ def knapsack (input : Seq [Int ]): Iterator [Set [(Int , Int )]] =
5
+ input.zipWithIndex.toSet.subsets.filter(_.toSeq.map(_._1).sum == 150 )
6
+
7
+ def part1 (input : Seq [Int ]): Int = knapsack(input).size
8
+
9
+ def part2 (input : Seq [Int ]): Int =
10
+ val occurrences = knapsack(input).toSeq.groupBy(_.size)
11
+ occurrences(occurrences.keys.min).size
12
+
13
+ def main (args : Array [String ]): Unit =
14
+ val data = io.Source .fromResource(" AdventOfCode2015/Day17.txt" ).getLines().map(_.toInt).toSeq
15
+ println(part1(data))
16
+ println(part2(data))
Original file line number Diff line number Diff line change
1
+ package AdventOfCode2015
2
+
3
+ import org .scalatest .funsuite .AnyFunSuite
4
+
5
+ class Day17Suite extends AnyFunSuite
6
+ // No unit tests possible
You can’t perform that action at this time.
0 commit comments