using ChatGPT to help solve Project Euler problems

Since I started playing with (and learning about) ChatGPT recently, I’ve been thinking about possible use cases where this kind of thing could actually help me out. I’ve watched the episodes of The AI Bot Show where they show how it can be used with D&D and with board game design, and that’s fun, but not directly relevant to me right now.

I realized today that trying to use ChatGPT to help me solve Project Euler problems might be an interesting exercise, and a bit more relevant for me. My intention wouldn’t be to get ChatGPT to just spit out the answers, but to use it as an assistant to help me figure out the problem. So I started playing around with that.

First, I realized that I haven’t touched Project Euler since 2022, and haven’t actually solved a problem since 2015! I’d solved problem 72 on April 9, 2015, apparently. And I started work on problem 73 in May 2022, but didn’t get very far with it. So I had to spend some time just spinning things up and refreshing my memory on where everything was and how it all worked.

Having done that, I found that I’d already written a working “brute force” solution for the problem, and used it to solve the simple case (where the limit value is 8), but not the actual problem (where the limit is 12,000). Well, it turns out that the brute force solution worked fine with the actual value, and ran in just a second, so there was no need to do anything more complicated.

Plugging in the correct answer for this problem unlocks a PDF that explains some better solutions to the problem. But I had trouble following it, so I did ask ChatGPT to help me figure some stuff out there. But then I hit a wall, since I didn’t understand a particular mathematical notation used in the PDF, and I can’t easily paste it into ChatGPT and ask it to explain it. (I think I might need to figure out LaTeX or something…) It’s got to do with Farey sequences and Stern-Brocot trees, and I don’t understand any of that. Oh well. I do want to sit down and work on this some more, but it’s 5 PM now, and I should really take a break for dinner some time soon.

One thing I tried with ChatGPT was pasting in a pseudo-code solution to the problem (the simplest one from the PDF) and asking it to convert it to C#. It did a good job of that, and surprisingly even filled in a method that was called in the pseudo-code but not defined (a GCD method). And it even explained that GCD was short for “greatest common divisor,” and explained what that means. So that was kind of cool.

I was curious to see if other people have played around with using ChatGPT for help with Euler problems, so I did some web searching on that. I found a thread on the Euler forums, from late 2022, where there was a bit of talk about it. And here’s a GitHub repo where somebody just fed a bunch of Euler problems to ChatGPT to see how good it would be at solving them correctly. The results are interesting.

Back on the subject of ChatGPT and similar AI tools in general, I’m still listening to podcasts, reading articles, and playing around with stuff. I guess I’m convinced now that it’s not all snake oil, at least. But I haven’t talked myself into paying for ChatGPT Plus or a paid Poe subscription yet.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.