-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package day10 | ||
|
||
import scala.io.Source.fromFile | ||
|
||
val groupNums = raw"(.)\1*".r | ||
|
||
def nextNums(s: String) = groupNums | ||
.findAllIn(s) | ||
.map { xs => s"${xs.length}${xs.head}" } | ||
.mkString | ||
|
||
def solution(input: String)(n: Int) = | ||
(1 to n).foldLeft(input) { (acc, _) => nextNums(acc) }.length | ||
|
||
@main def main() = | ||
val input = fromFile(".cache/10.txt").mkString.trim | ||
val solver = solution(input) | ||
|
||
val part1 = solver(40) | ||
println(part1) | ||
|
||
val part2 = solver(50) | ||
println(part2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import munit.FunSuite | ||
import day10.* | ||
|
||
class Day10Tests extends FunSuite: | ||
test("Part 1"): | ||
Seq("1", "11", "21", "1211", "111221", "312211") | ||
.sliding(2) | ||
.map { case Seq(a, b) => assertEquals(nextNums(a), b) } |