r/adventofcode • • 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

14 comments sorted by

16

u/jeroenheijmans 9h ago

Check out https://jeroenheijmans.github.io/advent-of-code-surveys/ and click "Toggle data table...." in the first section, it has these numbers for Prolog:

2018 -  5 (0.5%)
2019 -  3 (0.2%)
2020 -  6 (0.3%)
2021 - 11 (0.3%)
2022 -  9 (0.2%)
2023 -  9 (0.3%)
2024 - 11 (0.3%)
2025 -  5 (0.2%)
2026 - ?? (???%)

So quite a handful, more typically than Racket, Smalltalk, Brainf*ck, COBOL, Erlang, Powershell, and several others!

Personally I was taught Prolog in uni around 2002 and absolutely loved the programming language. I mean, come on: a language that quite often replies with just "No!" - what's not to love!? :D

2

u/airfighter001 4h ago

I have completed Day 1 in Cobol just a few hours ago, just because I've said that I'd do at least one day at some point for like 3 years by now and never got around to do it.

And honestly, so much respect to the people who complete not one day but entire years in Cobol. While not the hardest language to write in, doing anything that's more than some pretty basic computation just feels so convoluted compared to any other language I know. I couldn't make myself do that for 12 or 25 days.

14

u/gredr 9h ago

Prolog is neat, and learning it will make you a better programmer.

5

u/flwyd 8h ago

I've definitely considered doing a whole AoC season in Prolog, but it hasn't yet come to the top of my priority queue.

Advent of Code is a good opportunity to take a whole new programming paradigm and figure out how you can use it to solve a problem that you know how to solve in a more familiar paradigm. So give Prolog a try!

4

u/Pttrnr 6h ago

"Perl 7" is the bigger problem

2

u/thondat 8h ago

not using it this year, but i've done some AoC challenges in Prolog before to learn the language. it is alien compared to ALGOL-likes, and considerably different from Lisps and MLs as well. but it can be useful once you get the hang of unification and backtracking. SWI-Prolog (and AFAIK Scryer too now) has e.g. clpfd (Constraint Logic Programming over Finite Domains) which extends the language to make it convenient for satisfying integer constraints: something for which you would use PuLP or z3 or some other solver library in another language. there's also Definite Clause Grammars where you write a grammar in what looks quite similar to EBNF but is actually Prolog code. this is useful for parsing structured input, but can also be used for threading state. all in all, i'm still fascinated and will probably revisit Prolog some time.

2

u/Immediate_Form7831 7h ago

I have done a few puzzles in Prolog. Not many, but some puzzles lend themselves very well to solving in Prolog.

2

u/zeekar 6h ago

I've done some days in Prolog. I have a random language picker with 180 options and each day I let it surprise me.

2

u/East_Nefariousness75 6h ago

I'm planning to do every day with a different language. One of them will be prolog

1

u/l_tonz 5h 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).

1

u/ffrkAnonymous 5h ago

Not me. But only because my attempts to learn Prolog have failed so far. 

1

u/bolusmjak 43m ago

Been using Prolog for a few years. This year is no different.

1

u/Akari202 38m ago

My goal this year is a different language of the alphabet each day. I’m planning on prolog for p