Solve Project Euler in Egison

Jul 2, 2015

Solutions of Project Euler's problems in Egison are interesting demonstrations of Egison.
I have been sometimes writing solutions for these problems.
Actually, some problems helped me to find new ideas or fix performance issues in Egison.

Setting Up Environment

We have prepared the utility libraries to solve Project Euler.
We can install them with the following commands.

% mkdir $HOME/egison-libs % cd$HOME/egison-libs
% git clone https://github.com/egison-libs/project-euler.git
% cd project-euler
% ./install.sh
% cd ..
% git clone https://github.com/egison-libs/prime-numbers.git
% cd prime-numbers
% ./install.sh

The usage of these libraries are in the following pages.

demo.egi
% egison -t demo.egi
1299721

Simple Example

Briefly, Egison is a programming language with the following features.

• Functional programming with lazy evaluation strategy
• Strong pattern-matching facility

The first feature is useful to solve any problems in Project Euler.

The second feature is Egison's original key feature.
This feature is useful to solve problems for those we need to write complex enumeration.

Let me show a simple example.
This example is from Problem 33.
It seems obvious that we need to write a function that works as follow.

The work of the above rotate function is very easy, but tidy to write by ourselves.
Actually, we can write it easily using pattern-matching in Egison as follow.

Thus, Egison's pattern-matching makes programs concise by replacing tidy parts of programs with simple pattern-matching expressions.
We can find more interesting examples for more difficult problems.

Recent Tweets

This website in other langauge: English, 日本語