Skip to content(if available)orjump to list(if available)

Solving the first 100 Project Euler problems using 100 languages

moomin

Worth emphasising: Project Euler is a mathematical computation challenge, not a programming challenge like Advent of Code. The principal skill is algorithm design and as the problems progress you need to do more and more maths before you start coding.

LPisGood

Math is to computer science as physics is to mechanical engineering, so I feel like there isn’t a massive distinction.

xboxnolifes

They didn't say computer science, that said programming.

KeplerBoy

Let's just say you need a vastly different level of maths to succeed at project euler compared to aoc.

fuhsnn

Personal experience: I stopped at a point where brute-forcing started to feel "unwelcomed", I think it was this one: https://martin-ueding.de/posts/project-euler-solution-66-dio...

dark-star

I would argue that the later Advent of Code challenges (especially from the last 3 or 4 years) are very similar to (early to mid-tier) Project Euler challenges in that you cannot start before giving it a good hour or so of thinking

thaumasiotes

Do you ever need to start coding? I thought it was a requirement of the project that problems be solvable with pencil and paper.

mudita

While some problems are actually solvable with just pencil and paper, this is not a requirement and the intention of the project is that problems will be solved with a combination of insight and coding.

From the Project Euler website:

"Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems."

wholinator2

Well you probably _could_ whiteboard it but some of them are about extending a pattern to the millionth term. If you're really smart you might be able to find a closed form to get there quick, but you can also just program the basic rule and iterate

KeplerBoy

Afaik most of them require you to find the trillionth term, rendering naïve approaches futile.

marsten

For the harder Euler problems you usually need a combination of mathematical insight and good coding technique. Each problem typically provides sample values for smaller instances of the problem, which you can confirm with a straightforward solution approach. Then the actual problem will be to calculate f(10^500) or some absurd value that requires insight to make tractable. They are extremely good challenges overall.

null

[deleted]

llm_trw

Advent of code is not a programming challage, it is a reading the spec challage.

drysine

Not the last 3-5 days.

llm_trw

Got a link? I tried it a long time ago and decided that I got enough misleading specs at work.

7thaccount

I wonder which ones the author liked the most and which they disliked the most. I didn't see any comments on that. If they're on HN, it'd be cool to find out.

middayc

The author wrote a short comment about each language in the following blogposts:

https://log.schemescape.com/posts/100-languages/index.html

fuzzythinker

It's hard to form a good opinion of a language if the knowledge of it is shallow, which I'm inclined to believe based on using 100 languages. More interesting is why the author decide to use a particular language for each problem.

gre

Why did I expect 10,000 files?

acrophiliac

I'm totally with you, bro. Maybe the headline should have been "Solving 100 project Euler problems using a different programming language for each one" but that's probably way too verbose.

karmakaze

I expected 100x100 programs too without thinking how unreasonable that is. But sometimes it's hard to gauge what's unreasonable on HN.

"Solving the first 100 Project Euler problems in as many languages" does the trick and is only one character longer.

drysine

>how unreasonable that is

It was a year or two ago.

null

[deleted]

archargelod

From one of blog posts [0]:

    Nim

    Nim is the language that impressed me the most in this batch. Everything I thought would be a problem (significant whitespace, choose-your-own-function syntax, intermediate C compliation step) didn't bother me at all. The small sample of the standard library I played with was a little quirky, but Nim seems like excellent bang for your buck.

    Notes:

    - Release binary was only 120 KB (linked against libc)!
    - Thought I'd dislike the syntax, but it was fine
    - Really easy to get started, many things "just worked" (e.g. grabbing a slice of an array)
    - Didn't have to specify too many types, but still ran fast
    - Fast compilation
    - Didn't like the "hints" it spews out during compilation, even for nim r (build and run)
    - Why did all take an anonymous function, but foldl took just an expression (with a and b seemingly picked out of thin air) -- is foldl a macro?
    - Nim might be a good language for hobby projects because it's easy, fast, and produces small binaries
    - I wonder what the debugging experience is like -- if it's decent, I might be writing a lot more Nim in the future!

This exactly my thoughts on Nim and why I use it almost exclusively for all my hobby projects.

0-https://log.schemescape.com/posts/programming-languages/100-...

giancarlostoro

Nim is a gem and I wish it was more mainstream than it is. Its older than both Rust and Go.

tocs3

I am interested in seeing Verilog used as one of the 100 languages.I have been wondering how it would be to use some sort of hardware description language to solve some of (all?)the problems. I worked thru the first half of "Nand to Tetris" [1] and thought I might try working some of the problems with that.

[1] https://www.nand2tetris.org/

hmng

From one of the blog posts:

> 8080 assembly (Altair 8800) > > First time I've heard of binary-coded decimals

I’m really surprised with that, that someone with such broad interests never heard of BCD. I mean, there’s is always something new to learn all the time, don’t get me wrong, nothing to criticize, just plain surprised. Wonder if that is just something older people came across?

munchler

Old PL/I programmer here. I’m still trying to forget BCD’s from the 80’s!

drysine

I learned about BCD when I was learning x86 assembly and have never came across them later. They are gone in x64.

adhamsalama

I did learn binary-coded decimals in college 5 years ago.

kazinator

Pretty sure the first one should be done with a closed form formula:

lcm(3, 5) = 15. So there is a repeating cell of values every 15 which we can take advantage of:

  0, 3, 5, 6, 9, 10, 12,

  + 15  ->               15, 18, 20, 21, 24, 25, 27,

                         + 15  ->                    30, 33, 35, 36, 39, 40, 42

                
The last cell ending in 1000 is incomplete.

entaloneralie

Wowow! this is fantastic, so many exciting and weird languages in there, even Mouse-83 is in the list!

It was really nice to read about the author's impression of each language.

Well done

joshuamcginnis

Let's say an experienced engineer is starting Euler for the first time. What's the best way to approach it given that many of the problems require some prerequisite algorithmic knowledge to solve? Is there a good method for approaching Euler and LeetCode problems with new eyes aside from reading the solutions first, studying them and then solving it many times until committed to memory?

eru

IMHO, Project Euler is a lot harder than LeetCode and requires a lot more math.

I'm not sure why you would want to solve it many times and committing those solutions to memory? I think you would be better off using some of the time to just read some text books?

For some of Project Euler https://www2.math.upenn.edu/~wilf/gfology2.pdf is a good math book to consult. The techniques in there will allow you to solve some of the problems with just pen and paper (and perhaps a pocket calculator, if you are too lazy to do the arithmetic by hand, but no need for a full blown programmable computer), especially the first few problems if memory serves right. Eg where they ask you to add up the first few billion even terms of the Fibonacci numbers and similar; you can just derive a simple closed formula and evaluate that by hand.

xzyyyz

Project Euler is collection of puzzles based on math. The coding and designs skills are completely secondary to the math. The algorithms (except for computational number theory, computation geometry) are completely secondary. So it is knowledge of math that is barrier.

I keep learning math (and, sometimes, relatively new development in math) by solving problems. To start, I would recommend reading G.H. Hardy & E.M. Wright "An Introduction to the Theory of Numbers".

With LeetCode -- this is more traditional exercise in coding. I did not pay much attention to it. So, sorry, cannot provide any advice

abecedarius

Really it's fine to just start. At some point you may get stuck and want to learn more math, but when I did the first ~45 I certainly had not read generatingfunctionology or Hardy and Wright.

null

[deleted]

omoikane

I like how the author used four different variants of BASIC.

krick

I'm curious if they are really, like, different. All Basic that I've seen in my life was a minuscule bit of VB and some really ancient programming book I've picked up when I was like 7 y.o. and didn't really have access to a computer.

omoikane

I remember QBasic was notably different from Applesoft Basic in that QBasic did not require line numbers, and one of the demo programs (remline.bas) removed line numbers for you. Of the variants used by this author, the Commodore Basic variant is distinct in being the only one with line numbers. The others all look very similar.

MaysonL

Back in the day, over a decade or so, I wrote a few megabytes of VAX Basic. The language, and the code I wrote, at the end of that period looke nothing like it did at the beginning. So yes, it’s quite likely that the Basics are substantially different.

cgh

AmigaBasic is quite different from Commodore Basic v2.0, and that’s within the same company.

nradov

That's cute but if you can't solve those problems in INTERCAL then can you even call yourself a programmer? (But seriously this is pretty cool.)

callc

I solved the first 100 problems a long time ago before learning the best practices we learn as professional engineers.

It’s alien code now.