Advent of Code 2021 - Day 21

This topic is about Day 21 of the Advent of Code 2021.

We have a private leaderboard (shared with users of Erlang Forums):

https://adventofcode.com/2021/leaderboard/private/view/370884

The entry code is:
370884-a6a71927

Fun puzzle today.

Here is my solution:

For now only Part 1, as I am still working on Part 2:


round =
  Stream.unfold(0, &{&1, &1 + 1})
  |> Stream.scan({{0, p1}, {0, p2}}, fn n, {{s, p}, other} ->
    p =
      case rem(p + 6 + n * 9, 10) do
        0 -> 10
        v -> v
      end

    {other, {s + p, p}}
  end)
  |> Enum.take_while(fn {{s, _}, {_, _}} -> s < 1000 end)

{rounds, {{loser, _}, _}} = {length(round), List.last(round)}

rounds * 3 * loser

Oh sorry, wrong reply button

Enjoyed this one!

First star with only streams: advent-of-code-2021/first.ex at main · rhruiz/advent-of-code-2021 · GitHub

Still figuring out why my second star does not generate enough branching universes

Really enjoyed todays puzzle - had to step away and work between parts 1 and 2 that gave me enough time to work out a good portion of the solution.