Skip to content

Commit 5f94720

Browse files
committed
Year 2015 Day 15
1 parent 894bc43 commit 5f94720

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,4 @@ The minimal SBT project provides:
224224
| 12 | [JSAbacusFramework.io](https://adventofcode.com/2015/day/12) | [Source](src/main/scala/AdventOfCode2015/Day12.scala) |
225225
| 13 | [Knights of the Dinner Table](https://adventofcode.com/2015/day/13) | [Source](src/main/scala/AdventOfCode2015/Day13.scala) |
226226
| 14 | [Reindeer Olympics](https://adventofcode.com/2015/day/14) | [Source](src/main/scala/AdventOfCode2015/Day14.scala) |
227+
| 15 | [Science for Hungry People](https://adventofcode.com/2015/day/15) | [Source](src/main/scala/AdventOfCode2015/Day15.scala) |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sugar: capacity 3, durability 0, flavor 0, texture -3, calories 2
2+
Sprinkles: capacity -3, durability 3, flavor 0, texture 0, calories 9
3+
Candy: capacity -1, durability 0, flavor 4, texture 0, calories 1
4+
Chocolate: capacity 0, durability 0, flavor -2, texture 2, calories 8
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package AdventOfCode2015
2+
3+
object Day15:
4+
def recipes(input: Seq[String]): Iterator[Seq[Int]] =
5+
val ingredients = input.map(_.split("[^-\\d]+").tail.map(_.toInt))
6+
def range(offset: Int) = Iterator.range(0, 101 - offset)
7+
for
8+
a <- range(0)
9+
b <- range(a)
10+
c <- range(a + b)
11+
d <- range(a + b + c)
12+
if a + b + c + d == 100
13+
yield Seq(a, b, c, d).zip(ingredients).map((k, i) => i.map(_ * k)).transpose.map(_.sum.max(0))
14+
15+
def part1(input: Seq[String]): Int = recipes(input).map(_.init.product).max
16+
17+
def part2(input: Seq[String]): Int = recipes(input).filter(_.last == 500).map(_.init.product).max
18+
19+
def main(args: Array[String]): Unit =
20+
val data = io.Source.fromResource("AdventOfCode2015/Day15.txt").getLines().toSeq
21+
println(part1(data))
22+
println(part2(data))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package AdventOfCode2015
2+
3+
import org.scalatest.funsuite.AnyFunSuite
4+
5+
class Day15Suite extends AnyFunSuite
6+
// No unit tests possible

0 commit comments

Comments
 (0)