Skip to content

Commit

Permalink
Solved day 11
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianCassayre committed Dec 11, 2024
1 parent f15c913 commit a0f5aaf
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ _My solutions to the 2024 edition of [Advent of Code](https://adventofcode.com/2
| **[08](https://adventofcode.com/2024/day/8)** | [solution](src/main/scala/adventofcode/solutions/Day08.scala) |
| **[09](https://adventofcode.com/2024/day/9)** | [solution](src/main/scala/adventofcode/solutions/Day09.scala) |
| **[10](https://adventofcode.com/2024/day/10)** | [solution](src/main/scala/adventofcode/solutions/Day10.scala) |
| **[11](https://adventofcode.com/2024/day/11)** | [](src/main/scala/adventofcode/solutions/Day11.scala) |
| **[11](https://adventofcode.com/2024/day/11)** | [solution](src/main/scala/adventofcode/solutions/Day11.scala) |
| **[12](https://adventofcode.com/2024/day/12)** | [](src/main/scala/adventofcode/solutions/Day12.scala) |
| **[13](https://adventofcode.com/2024/day/13)** | [](src/main/scala/adventofcode/solutions/Day13.scala) |
| **[14](https://adventofcode.com/2024/day/14)** | [](src/main/scala/adventofcode/solutions/Day14.scala) |
Expand Down
1 change: 1 addition & 0 deletions input/11.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9759 0 256219 60 1175776 113 6 92833
1 change: 1 addition & 0 deletions output/11-1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
186996
1 change: 1 addition & 0 deletions output/11-2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
221683913164898
27 changes: 27 additions & 0 deletions src/main/scala/adventofcode/solutions/Day11.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package adventofcode.solutions

import adventofcode.Definitions.*

import scala.collection.View

@main def Day11 = Day(11) { (input, part) =>

val initialStones = input.toLines.head.split(" ").map(_.toLong -> 1L).toMap

def evolve(count: Int): Long =
View.iterate(initialStones, count + 1)(_.toSeq.flatMap((value, count) =>
value match
case 0 => Seq(1L)
case v if v.toString.length % 2 == 0 =>
val (l, r) = v.toString.splitAt(v.toString.length / 2)
Seq(l, r).map(_.toLong)
case v => Seq(v * 2024)
match
case seq => seq.map(_ -> count)
).groupBy((k, _) => k).view.mapValues(_.map((_, c) => c).sum).toMap).last.values.sum

part(1) = evolve(25)

part(2) = evolve(75)

}

0 comments on commit a0f5aaf

Please sign in to comment.