## What is the best language for Project Euler?

In this forum members can discuss topics about specific programming languages.
Elihu5991
Posts: 4
Joined: Sun Sep 25, 2011 5:06 am

### What is the best language for Project Euler?

I'm looking at doing Project Euler problems. I'm not sure what language I should learn. I know a little of each language, but am happy t delve more into a language so I can accomplish the Euler problems.

PurpleBlu3s
Posts: 73
Joined: Mon Sep 19, 2011 5:49 pm

### Re: What is the best language for Project Euler?

You can solve PE problems in any language you want - of course some languages have better capabilities for certain things and will be better for some problems, however, certainly if you're just starting, any language will do. I started doing Project Euler to help learn a couple of new languages and I feel it has really helped. I use a mixture of Java, C, and J (and sometimes pencil/paper).

What languages do you want to learn the most? I would start there.

Cerium
Posts: 8
Joined: Sun Oct 11, 2009 11:26 am

### Re: What is the best language for Project Euler?

@PurpleBlu3s : I see your point but I'm not sure I agree.

In fact *every* language is suitable for PE especially at the begining but from my own experience I solve around 120 (more or less) problem in C or C++, and now I solve them with Python and you know what? Maybe it's slower if you're bruteforcing something but I do not spend a huge amount of time dealing with IO (for instance with problems where the input is in a file), or with permutations/combinations (see itertools modules), or dealing with big integer (no need for GMP) Python already deal with them. So even if you can solve all problems in language XYZ there's probably some language that are more fun and let you concentrate yourself on the problem rather than the "boilerplate" (IO/big integers/permutations etc)

BTW I talk about Python because I'm a huge fan, but there's probably some other great languages to use Ruby for instance or some functionnal languages.

PurpleBlu3s
Posts: 73
Joined: Mon Sep 19, 2011 5:49 pm

### Re: What is the best language for Project Euler?

Cerium wrote:@PurpleBlu3s : I see your point but I'm not sure I agree.

In fact *every* language is suitable for PE especially at the begining but from my own experience I solve around 120 (more or less) problem in C or C++, and now I solve them with Python and you know what? Maybe it's slower if you're bruteforcing something but I do not spend a huge amount of time dealing with IO (for instance with problems where the input is in a file), or with permutations/combinations (see itertools modules), or dealing with big integer (no need for GMP) Python already deal with them. So even if you can solve all problems in language XYZ there's probably some language that are more fun and let you concentrate yourself on the problem rather than the "boilerplate" (IO/big integers/permutations etc)

BTW I talk about Python because I'm a huge fan, but there's probably some other great languages to use Ruby for instance or some functionnal languages.
I would say my point was more relevant for easier problems. I also agree with what you said. Some languages do allow for you to focus more on the essence of a problem. I haven't yet solved any problems with an id greater than 100 so I can only speak for solving problems below that.

Elihu5991
Posts: 4
Joined: Sun Sep 25, 2011 5:06 am

### Re: What is the best language for Project Euler?

I have little knowledge in C, C++, Javascript and Python (and know far more in a few others that aren't elated to project euler). I'm looking for a language to stick to (maybe too), as I'll probably learn faster with less languages on my plate. Though I am happy to learn something completely different.

mwm
Posts: 3
Joined: Tue Sep 27, 2011 11:24 pm

### Re: What is the best language for Project Euler?

Odd that nobody talked about what features are useful for working on the problems.

So I'll start. #1 for me - by a long shot - is a REPL!

On the off chance you don't know, that's a Read-Eval-Print Loop. Basically, it's a program that lets you type in strings from the programming language, evaluates them, and then prints the result. Sort of a calculator programmable in the language of choice. I typically tackle a problem by writing a function I think will work, loading that code, then trying it on a few values "by hand". When I'm happy with that, I can write a main function to wrap it so I can use it from the command line, but for most of the problems I just feed it the initial values needed for the solution.

Second would be some form of lazy list and/or stream structure. A lot (well, of the few I've looked at) of the problems deal with the properties of sequences of numbers. Having a list of all the primes, or naturals, or whatever that fit in main memory around has been handy.

That said, people manage to solve them without these facilities. They just make it a little easier - at least for me.

Personally, I'm using a lot of haskell, falling back to Python if I decide I want a mutable object (as I'm still learning haskell), except for a couple of times when I've just written a shell script.

Which leads to the question - how do I get a language added to the list of possible languages?

elendiastarman
Posts: 410
Joined: Sat Dec 22, 2007 8:15 pm

### Re: What is the best language for Project Euler?

mwm wrote:Which leads to the question - how do I get a language added to the list of possible languages?
What many people have done is make a new thread for that language and ask for it to be added. euler usually gets to it within 24 hours.
Want some
3.14159265358979323846264338327950288419716939937510
58209749445923078164062862089986280348253421170679...?

lrhehe
Posts: 4
Joined: Sun Dec 11, 2011 1:10 pm

### Re: What is the best language for Project Euler?

Python

cool and easy to learn
numpy.py and scipy.py are good to math

Posts: 3
Joined: Mon Oct 08, 2012 12:24 pm

### Re: What is the best language for Project Euler?

Yes, Python is really a very beautiful language and fast to code programs. Even you have a Complex Data type available in Python.
You can many Scientific Libraries of Python to develop complex problems.
Some of the Python Scientific libraries are:
1. matplotlib, a MATLAB-like plotting library.
2. NumPy, a library that adds support for the manipulation of large, multi-dimensional arrays and matrices.
3. SciPy, a large library of scientific tools.
Just there is one problem, it takes little bit longer for the program to start up.
Check out this link : http://www.stat.washington.edu/~hoytak/ ... ython.html for (10 Reasons why Python Rocks for Research).

thedoctar
Posts: 74
Joined: Fri Apr 15, 2011 10:57 am
Location: Sydney, Australia

### Re: What is the best language for Project Euler?

I've used python to solve all problems I've solved so far. And they pretty much all are under a minute.
Cerium wrote:@PurpleBlu3s : I see your point but I'm not sure I agree.

In fact *every* language is suitable for PE especially at the begining but from my own experience I solve around 120 (more or less) problem in C or C++, and now I solve them with Python and you know what? Maybe it's slower if you're bruteforcing something but I do not spend a huge amount of time dealing with IO (for instance with problems where the input is in a file), or with permutations/combinations (see itertools modules), or dealing with big integer (no need for GMP) Python already deal with them. So even if you can solve all problems in language XYZ there's probably some language that are more fun and let you concentrate yourself on the problem rather than the "boilerplate" (IO/big integers/permutations etc)

BTW I talk about Python because I'm a huge fan, but there's probably some other great languages to use Ruby for instance or some functionnal languages.
I completely agree with your sentiments on Python. Python makes programming easy, and deals with the details so you can focus on the algorithm.
4x Intel(R) Core(TM) i3-2330M CPU @ 2.20GHz

fabas indulcet fames

ecbrown
Posts: 1
Joined: Sun Dec 09, 2012 12:02 am

### Re: What is the best language for Project Euler?

Mathematica.

basica
Posts: 2
Joined: Mon Jan 28, 2013 12:30 pm
Location: Southern Hemisphere

### Re: What is the best language for Project Euler?

I've been teaching myself to program over the last few months and I only really know Python at this point (though I have been tinkering with PHP as well) and I find that it's useful enough to solve the problems I throw at it. I do feel sometimes that I'm 'cheating' by using some inbuilt functionality that exists rather than manually doing it (such as sorting, or some mathematical functions) and I am torn whether or not I am just getting to the root of the problem thanks to this inbuilt functionality or I'm simply bypassing the 'hard bits'.

I also noticed in some of the solutions posted are just one liners thanks to the programming language of choice and it also makes me think if that's also cheating, but meh. I say pick the one you're the most comfortable with and go from there. When you're really comfortable with one you can move to others and be a bit more discerning I guess.
For a man to conquer himself is the first and noblest of all victories. - Plato

whakamaru
Posts: 47
Joined: Thu May 06, 2010 10:08 pm

### Re: What is the best language for Project Euler?

Assembly is the fastest. So, maybe work out the logic in a high-level language, then re-write it into ASM. That might take ages, but the speed is worth the effort.

alex914n
Posts: 18
Joined: Wed Feb 13, 2013 3:55 am

### Re: What is the best language for Project Euler?

Fastest is not necessarily the best, except in very specialized cases!

Computing power is cheap, peoples' time is expensive.
A solution that I can program in less than an hour, which will run in, say, 10", is much better for me than a solution that runs in 10 ms but needs days to code!

Expressiveness and flexibility are the keys to productivity.

nicoo
Posts: 4
Joined: Thu May 16, 2013 5:23 pm

### Re: What is the best language for Project Euler?

alex914n wrote:Fastest is not necessarily the best, except in very specialized cases!
Computing power is cheap, peoples' time is expensive.
I agree: there is no point, IMHO, in over-optimizing your solutions (except if your goal is to learn how to write more efficient code).

That's why I would recommend using a language:
• that doesn't require you to write boilerplate (for I/O, basic data-structures, big integers, ...);
• that you are familiar with (if any).
Personally, I use OCaml and Haskell a lot (I find functional style really efficient for PE (and other things)), and sometimes write in C (because I like to keep my C-skills sharp).
alex914n wrote: A solution that I can program in less than an hour, which will run in, say, 10", is much better for me than a solution that runs in 10 ms but needs days to code!
To be honest, I have 2 problems with this statement :
• rewriting the same algorithm in another language shouldn't bring an $6\cdot 10^4$-fold improvement (unless the compiler/runtime is exceptionally bad, but then you probably shouldn't use it in the first place);
• a solution that takes 10" might be extremely unsatisfying, and can probably be improved using mathematical or algorithmic tricks.
Anyways, for that last part, it is a matter of taste.