Advent of Code 2022 Day 25 - Discussions

This topic is about Day 25 of the Advent of Code 2022 .

Finally! In a few hours we get to see what the 50 starred animation looks like! Going to miss this! See you all next year!

Link to our leaderboard:

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

The entry code is:
370884-a6a71927

We are at 196 right now and 200 is the cap, in case the leaderboard fills up and you are unable to join, please join the following:

https://adventofcode.com/2022/leaderboard/private/view/257223

And the code for this leaderboard is: 257223-1bcda624

Good luck and let’s meet again next year, same times, same place, same language :v:

3 Likes

Merry Chrismas everyone :christmas_tree: :partying_face:

main(File) ->
    {ok, RawData} = file:read_file(File),
    Data = [ binary_to_list(Line) || Line <- binary:split(RawData, <<"\n">>, [global, trim]) ],
    io:format("part 1: ~p~n", [solve1(Data)]).

solve1(Data) ->
    encode_snafu(lists:sum([ parse_snafu(N) || N <- Data ])).

parse_snafu(Number) ->
    lists:sum([ do_parse_snafu(X) || X <- lists:enumerate(0, lists:reverse(Number)) ]).

do_parse_snafu({Pos, X}) ->
    N = case X of
            $= -> -2;
            $- -> -1;
            $0 ->  0;
            $1 ->  1;
            $2 ->  2
        end,
    trunc(math:pow(5, Pos)) * N.

encode_snafu(X) ->
    lists:reverse(do_encode_snafu(X)).

do_encode_snafu(N) when N > 0 ->
    {C, NewN} = case N rem 5 of
                    3 -> {"=", N + 2};
                    4 -> {"-", N + 1};
                    V -> {integer_to_list(V), N}
                end,
    C ++ do_encode_snafu(NewN div 5);
do_encode_snafu(0) ->
    [].
3 Likes

Yeah today’s one was quite easy. The tricky bit was to figure out the negative encoding while putting it back to snafu. Did it with Elixir first as I was eager to see that end animation (Got disappointed though).

2 Likes