Advent of code..what is it?
Advent of code is an annual online programming event which usually happens in December every year. Each day you get set of two programming puzzles which you try to solve using any programming language of your choice, for more details you can read here. The important question is not what it is but important focus of this post is why doing it in ABAP? Read on!
Why doing it in ABAP…
Off late ABAP has gone so many changes it is very difficult to stay up to date. When I saw a tweet from Christian about this my initial reaction was to do it in ABAP why…read on?
Get comfortable with using eclipse.
Eclipse is everywhere and I believe this is the best chance to learn both the basic and advanced level. You can already see my theme is all set for Eclipse dark one and I plan to use maximum eclipse to accommodate all tasks.
Is it that easy working with eclipse for an ABAPer, I will say it takes some time to get habitual with multiple views but its great. After completing day 1 I am trying to find how do maintain text elements. Is it possible or not.. does not matter how basic the question is important is we all are trying to learn. This is one of the many questions which I hope to resolve during this journey. Just FYI I liked the bookmarks and outline feature?
Get comfortable with new ABAP features
This is another important reason to do AOC as we will try to use as much latest features of ABAP to arrive at the solution. For example for day1 part 1 puzzle I was able to use Reduce but for part2 used a old + new approach. Are my approaches the best of course not, they must be the worst, that is why I am writing here to learn from you guys how to do the things right new, short and concise way .
Part 1 solution
DATA(output) = REDUCE i( INIT sum = 0 FOR wa IN me->input_data NEXT sum = sum + ( floor( wa / 3 ) - 2 ) ). cl_demo_output=>display( output ).
Part 2 Solution
DATA(sum2) = 0. LOOP AT input_data ASSIGNING FIELD-SYMBOL(<fs>). DATA(sum3) = ( floor( <fs> / 3 ) - 2 ). sum2 += sum3. WHILE sum3 > 0. sum3 = ( floor( sum3 / 3 ) - 2 ). IF sum3 > 0. sum2 += sum3. ENDIF. ENDWHILE. ENDLOOP. cl_demo_output=>display( sum2 ).
Some how utilize the power of abapGit
Another important thing which I wanted to work on was abapGit. So I think no better way than this. My system has it now plus I am able to make my first push to remote repo here. I must say a great work done by Lars and other contributors?
What is next?
The plan is very simple try to solve these puzzles with ABAP. Share the solutions with the community for a feedback for a better solution. If few of you can join us in this journey it will be fun. As now I am aware Hendrik is doing this in ABAP and I am waiting for his solutions to get posted so as to learn how can things be better. Another side benefit of doing this is you get to know what else also exist for example we have similar kind of challenges which exist for serverless thanks to Gregor Wolf for letting us know.