Project Euler is a website dedicated to computational problems intended to be solved with computer programs.
At the time of this writing, it includes over 400 problems, with a new one added every week.
Problems are of varying difficulty but each is solvable in less than a minute using an efficient algorithm on a modestly powered computer.
I have already solved some of the problem, mainly using J (a language in the APL family) or Python.
Last year I learned ABAP and now, to test my skill with it, I decide to solve some of the Project Euler problem using ABAP.
To be able to execute ABAP programs, I have installed a SAP NetWeaver Trial Version ABAP (Windows) under VirtualBox.
The first problem (Multiples of 3 and 5) is not very difficult:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
My ABAP solution was the following (run the program to see the solution):
REPORT ZMLA_EULERO_001.
DATA: total TYPE INT4 VALUE 0,
limit TYPE INT4 VALUE 1000,
result TYPE STRING.
DO ( limit - 1 ) TIMES.
IF sy-index MOD 3 = 0.
total = total + sy-index.
CONTINUE.
ENDIF.
IF sy-index MOD 5 = 0.
total = total + sy-index.
CONTINUE.
ENDIF.
ENDDO.
result = |The result is { total }|.
WRITE / result.