The purpose of this site is to provide elegant code to problems on the Euler Project using the Ruby programming language.
Code Must Be Elegant
This site does not just provide any solution that works. It provides solutions that show off Ruby. The solutions try to use techniques that are fairly unique to Ruby so the reader can clearly see why Ruby provides an elegant way to solve problems that cannot be easily achieved in other languages.
You can think of this site as part “ode to Ruby” and part “exploration of the Euler problems”.
General Format of Each Solution
For each post I will first present the actual solution followed by a note or two about the solution.
In general the solutions will not use any complicated math. The goal is really more to explore good Ruby style and less about coming up with some obscure way of solving the problem using advanced math. So most solutions will take the simplest brute-force method. I’ll leave it to the reader to come up with a more advanced method using more advanced math.
Many solution will have tags. These tags note some element about the problem that is present may be present in other problems. So to see all problems related to a particular topic just click the tag.
Running the Solution
Each solution will be entirely contained so no external libraries should be needed to run them. For brevity sake we are leaving off the following standard Ruby script header that you should include in most of your scripts:
This is not necessary to run the script as you can just call ruby -w myscript.rb. But if you are running on a Mac or Unix-based operating system this header tells the operating system that the file should be run using the Ruby command. It also tells Ruby that it should run with warnings enabled (the -w flag). So with the header the command line is shortened to just myscript.rb.