r/adventofcode • u/SlayLeafSlug • 10h ago
Meme/Funny AoC in Prolog?!?!
I was filling in the unoficcial AoC survey
(⭐ Take the (~5min) Unofficial AoC 2026 Survey: https://forms.gle/JbZKoBqzG248Z6RV6 ⭐)
And I saw this:


Who the hell is out there doing AoC in Prolog😭
18
Upvotes
View all comments
1
u/l_tonz 6h ago
I have a solution in erlang which ressembles erlang
-module(aoc20260101).
%% API exports
-export([main/1]).
%%====================================================================
%% API functions
%%====================================================================
%% escript Entry point
main(_Args) ->
M = maps:new(),
Output = loop(M),
SortedMap = lists:keysort(2, maps:to_list(Output)),
Top3 = lists:nthtail(length(SortedMap) - 3, SortedMap),
%Least3 = lists:sublist(SortedMap, 3),
Keys = [K || {K,_} <- Top3],
Product = lists:foldl(
fun(X, Acc) ->
X * Acc
end,
1, Keys),
io:format("~w~n", [Product]),
erlang:halt(0).
loop(M) ->
case io:get_line("") of
eof ->
M;
Line ->
case string:to_integer(string:trim(Line)) of
{N, ""} ->
NewM = case maps:is_key(N, M) of
false ->
maps:put(N, 1, M);
true ->
Val = maps:get(N, M),
maps:put(N, Val + 1, M)
end,
loop(NewM);
_ ->
loop(M)
end
end.
%%====================================================================
%% Internal functions
%%====================================================================
%%
%%
%% Output:
%%
%% analyze your list of IDs. What do you get if you multiply together the three IDs which appear most often?
%% create a map and store the occurrences in that list. we can use an array.
%%
%% Input: list of numbers which are IDs
%%
%% details:
%%
%%
%%
%% notes/approach:
%%
%% we will need to parse every line. the id can be stored in an array, since the keys are ids. (keys are only two digits).