Skip to content

Commit 7a2e58f

Browse files
committed
Year 2015 Day 20
1 parent 1f873d8 commit 7a2e58f

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,4 @@ The minimal SBT project provides:
229229
| 17 | [No Such Thing as Too Much](https://adventofcode.com/2015/day/17) | [Source](src/main/scala/AdventOfCode2015/Day17.scala) |
230230
| 18 | [Like a GIF For Your Yard](https://adventofcode.com/2015/day/18) | [Source](src/main/scala/AdventOfCode2015/Day18.scala) |
231231
| 19 | [Medicine for Rudolph](https://adventofcode.com/2015/day/19) | [Source](src/main/scala/AdventOfCode2015/Day19.scala) |
232+
| 20 | [Infinite Elves and Infinite Houses](https://adventofcode.com/2015/day/20) | [Source](src/main/scala/AdventOfCode2015/Day20.scala) |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
29000000
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package AdventOfCode2015
2+
3+
object Day20:
4+
def part1(target: Int): Int =
5+
val limit = target / 10
6+
val houses = Array.fill(limit + 1)(10)
7+
for x <- 2 to limit; y <- x to limit by x do houses(y) += 10 * x
8+
houses.indexWhere(_ >= target)
9+
10+
def part2(target: Int): Int =
11+
val limit = target / 10
12+
val houses = Array.fill(limit + 1)(10)
13+
for x <- 2 to limit; y <- (x to limit by x).take(50) do houses(y) += 11 * x
14+
houses.indexWhere(_ >= target)
15+
16+
def main(args: Array[String]): Unit =
17+
val data = io.Source.fromResource("AdventOfCode2015/Day20.txt").mkString.trim.toInt
18+
println(part1(data))
19+
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 Day20Suite extends AnyFunSuite
6+
// No unit tests possible

0 commit comments

Comments
 (0)