Skip to Content

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.

To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Susan Keohan

    Hi Luca,

    I can sense a theme here in your recent blogs.  I am glad you are having fun with ABAP, and with Blogging as well.

    You should beef up your bio though – it would be nice to know more about you!

    Sue

    (0) 
      1. Susan Keohan

        Hi Luca,

        I think you may need to revisit your bio – and decide which elements you want to be public.  If you go to your profile, and then look on the right for ‘Edit Profile and Privacy’ and then choose ‘Privacy Settings’ you will be able to mark items for ‘Everyone’ to see!

        It’s tricky, I know.  I thought for months that my profile info was available for all to see, but in this *one instance* I was wrong!

        Cheers,
        Sue

        (0) 
  2. Graham Robinson

    Hi Luca,

    Have you considered putting these solutions in the wiki instead of blogs? Then you can crowdsource solutions to these problems amongst the whole SCN community and share both the problems and the results.

    Cheers

    Graham Robbo

    (0) 
    1. Former Member Post author

      Hi Graham,

      It is a good idea to use a wiki.

      Did you mean a wiki in SCN? I have not found it (but maybe I just looking in wrong directions).

      I used to document my solution using dokuwiki.

      MfG

      Luca.

      (0) 
      1. Graham Robinson

        Hi Luca,

        the ABAP Development wiki is at http://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Development+and+Programming

        Unfortunately it is not part of the new SCN platform yet so it seems to be very hard to find. ๐Ÿ˜

        I think there is the potential here for a community wide programming challenge.

        If you were suitably motivated you could create a page for each Project Euler Problem and people could choose to submit solutions for each. Then there could be a ranking system for the elegance and speed of each solution. Maybe a judging panel of a few respected ABAP Geeks.

        And in the spirit of “What would Marilyn Pratt do?” it might be worth reaching out to Laure Cetin to see if she has some other ideas around gamification.

        Cheers

        Graham Robbo

        (0) 

Leave a Reply