Project Euler / programming problems

For part one, was there any faster way than just sorting both lists? (For pt 2, I was able to find the linear solution)

1 Like

I do these all as inefficiently as possible.

Part 2 slow way
total = a1.each.sum do |x|
  x * a2.grep(x).length
end
1 Like

To regex, or not to regex?

Who am I kidding
do(n't)?\(\)|mul\(([0-9]+),([0-9]+)\)

^ I learned later this is “wrong” but I have been blessed by the input gods :pray:

3 Likes

You re-ally missed an opportunity with the phrasing there. Anyway, here is mine:

(don't\(\)|do\(\)|mul\((\d+),(\d+)\))

Was your theoretical problem not limiting it to three digits? If so I did the same.

1 Like

haha yeah I think it was supposed to be something like \d{1,3}, but I don’t think it mattered

1 Like

Advent of Code is open! This year there are just 12 problems scheduled, which should make it a lot more doable to get through the whole challenge by the end of the month! Also, there is no more global leaderboard; it sounds like that was getting impractical due to the popularity of the site and the rise of AI.

This year I’ll challenge myself to use some different and unusual language for each one. I’ll also limit my web searches to official docs and StackOverflow, so that I don’t get help from Google’s AI.

First one...

Emacs Lisp!

I’ve reset my private leaderboard; if you want to join again please DM me for the code.

UPDATES

For problem 2 I used PHP.

Among other things I learned that in PHP, "101" can be split into two equal substrings, since "1" == "01" is true :unamused_face:

For problem 3 I used GNU Octave. I got lucky - did not realize that numeric values were floating-point by default, and in fact I was within a factor of 100 of the point at which integer arithmetic stops working well (253).

For problem 4 I went back to the first programming language I ever learned and wrote my solution in GW-BASIC. It was really easy to get running with DOSBox installed via Nix! I had completely forgotten many things about the language, like how the logical operators work bitwise and so -1 is the typical “true” value.

I did part 1 of problem 5 in TeX (actually pdftex) and it was horrible. TeX has no data structures other than macros and 32-bit integer variables. I switched to pdftex to get access to an extra function \pdfstrcmp that I really needed to compare these numbers, since I didn’t want to have to figure out the string splitting and logic required to achieve 64-bit math. In the end I got confused about some spacing issues and found that randomly sticking a few more spaces in a couple of places made it all work. Then I took a look at part 2 and lost all motivation to continue, ugh.

2025-12-11: So, for problem 6 I went to a more normal language, Tcl. In Tcl it was kind of convenient to build up expressions with concatenation and simply evaluate them with expr. Blank spaces tended to just automatically disappear, leaving all the expressions neatly organized.

2025-12-13: I did this one in SQLite, proving that SQL is a real programming language! It was interesting to learn how to import data and also to discover that there’s a basic looping/recursion structure called WITH RECURSION available. Unfortunately, as far I as I can tell, it doesn’t support the kind of multi-path recursion I wanted for part 2, so I had to make my own little one-dimensional arrays of string-formatted numbers to keep track of all the data.

2025-12-22: I’ve been slowing down but did #8 in Lua. There wasn’t much of a challenge here, Lua is really simple. It just took a while to write it all out since Lua seems to require explicit loops for a lot of tasks that other languages have built-in support for. Luckily part 2 turned out to be really easy.

4 Likes

I was recently learning about uiua and problem 4 seemed like a good match for it!

Solution to part 1


Run it online

Using the “variable” P (actually it is rather a constant, uiua doesn’t have variables) is a bit of a hack and not in the spirit of the language, but I haven’t wrapped my head around fork yet. I think getting rid of the P would be necessary to solve part 2 in a clean way using do.

2 Likes

That language looks amazing! Definitely “different and unusual”!

Meanwhile I did part 1 of problem 5 in TeX and it was horrible. For example I had to do

\newlinechar=`\^^J

just to enable using newlines (typed as ^^J) in printed messages. Then I got completely derailed when I saw what part 2 was asking for, no idea how to approach it in a language without data structures.

I think I will skip ahead to problem 6 for now and use something less painful like Lua or Tcl to get myself back on track.

1 Like

That was one the toughest problem I have solved so far.
It took me, no joke, several months to finally get the answer.

Congrats on level 8!