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

24 Upvotes

19 comments sorted by

20

u/jeroenheijmans 2d 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

4

u/airfighter001 2d 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.

17

u/gredr 2d ago

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

7

u/flwyd 2d 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!

1

u/yolkyal 1d ago

I feel like I want this to be true but right off the bat you have to do a bunch of file-reading and input parsing which is never the nicest thing to be dealing with with a language you've just started learning.

2

u/flwyd 1d ago

My Advent of Code calendar:

  • October: Pick a language (or language family), start reading documentation and playing around.
  • November: Implement a runner library in the new language. The runner reads the input file as a list of lines, reads a file with expected answers, runs part1 and part2 functions, compares outputs with expected values, prints results, and times execution.
  • December: Solve puzzles without having to think about I/O or test case assertions.
  • January: Take care of all the tasks I didn't get around to in December because I was up late playing with code.

The time I spend flailing about in November usually means I've gotten used to several things that will be important in December (calling functions, building and splitting strings, compound structures). It also gives me a chance to write any utility functions that I'm going to want but that aren't available in a language with a thin standard library (like sorting and string manipulation in PostScript from 2024…). It's good to exercise before the competition begins :-)

1

u/yolkyal 23h ago

That's a very good idea, I'll try this in future 👍

5

u/Pttrnr 2d ago

"Perl 7" is the bigger problem

3

u/thondat 2d 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.

3

u/Immediate_Form7831 2d ago

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

3

u/zeekar 2d 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.

3

u/East_Nefariousness75 2d ago

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

2

u/bolusmjak 1d ago

I have done past years in Prolog. After solving day 1 in Prolog this year, I decided to try solving in CHR. It's actually surprisingly straightforward and fast.

https://gist.github.com/z5h/cda95f7cdaf9c9f4e8ebf5f7ed48a92b

1

u/l_tonz 2d 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 2d ago

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

1

u/Akari202 1d ago

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

1

u/kyleglowacki 1d ago

I took it in college 35 years ago. I could probably blunder through but what can I run it on? Does Ubuntu have apt get prolog?