Event Information
SAP Community Coding Challenge Series
It is with great pleasure that we announce a new community activity – the SAP Community Coding Challenge Series. The idea is that periodically SAP will post a coding challenge or puzzle for the community to solve. It will be something fun yet hopefully will teach something as well. It should be simple enough that most people could work on it over a lunch break but if you really want to solve the problem optimally might require some thoughtful research and experimentation.
For this first challenge, we will go to our technology roots in the SAP community and open with an ABAP coding challenge. This challenge can be performed in the SAP Cloud Platform ABAP Environment Trial (this is where our sample solution was tested).
https://developers.sap.com/tutorials/abap-environment-trial-onboarding.html
Voting is now LIVE!
To vote on the winner, simply go to this Community question. The finalist are all listed as answers. Upvote the answer you believe is best.
https://answers.sap.com/questions/13007129/sap-community-coding-challenge-march-2020.html
And if you want more details on the Special Award winners, Rich Heilman posted a blog about them here: https://blogs.sap.com/2020/03/17/sap-community-coding-challenge-series-march-2020-special-awards/
Midpoint Challenge Update:
Now that we are 1/2 way through the first challenge, we did a live stream to discuss the progress, judging and how to get started coding in the SAP Cloud Platform ABAP Environment Trial.
Challenge Directions:
Start with this line of code as the first line in your application. Requirement: make sure to cut and paste this line of code and NOT type it.
DATA(sentence) = `ABАP is excellent `.
Using the value in the variable sentence, programmatically determine the number of words in this variable and then count the number of UNIQUE letters in each word.
Your output should look like this:
The goal is to accomplish the task with as few lines of code as possible. Our sample implementation uses 9 lines including the data(sentence) and out->write lines. Can you do it in less?
Consider processing efficiency and ABAP best practices as well. How clean is your code? https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md Usage of Hungarian notation will be severely ridiculed. ?
Finally you must also explain why ABАP correctly has 4 unique letters.
Submission and Judging
Once you have a solution you are happy with, please email your submissions along with a link to your public SAP Community Profile to the community@sap.com inbox. Everyone has until March 15th, 23:59 Pacific Daylight Time (PDT) / UTC-7 to submit your coding solution. The community and developer advocates team at SAP will then do the first round of judging, narrowing down to 5 finalist that have the cleanest, most elegant, or most creative solutions. We will then post these 5 finalist in a community Q&A entry so that everyone will have a chance to vote on the best overall solution.
In the spirit of the immortal Stan Lee, the fabulous prize for the winner of the Coding Challenge will be a No-Prize. The coveted No-Prize also comes with the unending adulation and admiration of the community of fellow developers.
Hi Thomas,
Good initiative. Really appreciate it. And also "No-Prize" Haha
Number of Unique characters in ABAP - 4 ??
Yes – that’s part of the challenge to figure why that is the case. 😉
Sure some thing is 'special' in ABAP there 😉
This is why you should copy the "DATA(sentence)"-line 😉
Great challenge and magical award!
I stopped doing ABAP 7 years ago.. but this excites me. Specially, ABAP - 4 ?
I think, I should give a try and see how much developer left in me?
Hi Thomas,
Does the 9 lines include blank lines for neat formatting?
No we are only counting lines of code.
Nice challenge. It's possible with 8 lines of Code.
Clean Code? Challenge accepted. 😉
Clean code does not means Clean writed. It means you follow all the rules
https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md
Do one thing, do it well, do it only
you do a loooot of things
Dear Thomas,
as I love automated unit testing some questions to your requirement:
Love the challenge!
Cheers Klaus
Characters not letters
yes
upper/lower would be different characters
Your choice. We didn’t specify how to produce the output. The calculation itself is what we are after
Awesome challenge. Learned something new and would say it is possible in 6 statements. The ABAP case with 4 chars nice trick 🙂 Looking forward to your judgement.
I love a challenge but am wondering: is it solvable (without using brute force) on a NW 750 EHP 8 system or are newer ABAP syntax options needed to get it done in as few lines of code as possible?
Cheers
Bärbel
I’m sure it’s solvable there but might require a few more lines of code. Of course if you want to use the newest syntax, the SAP Cloud Platform ABAP Environment Trial is an easy solution.
I have a running code on 7.40 SP8 with just three lines of code -> so yes, it's possible on older releases
One line for the assignment, one for the split and one for the rest?
?
wrapping of a single line to multiple lines is still considered a single line right? <Limitation of ABAP 255 chars in a single line>
Yes. It’s fine to break a single line of code over multiple lines in the editor. That improves readability which is also an important factor here.
I am not sure to be able to do it better. And I have a CHECK … a LOOP …
but, it is dynamic, unreadable, … perfect developer code 🙂
And there is no hungarian notation ( for Matthew Billingham )
Not to be a spoilsport, Fred - but shouldn't "Number of words" be 3? ?
A yes ... need to move my check 🙂
After the good remark of Bärbel Winkler, I have to change the code, I replace a line by another line. So same score
MAybe there are other reasons 🙂
6 lines of code, beat me! 😀
As Thomas said on Twitter "Until you hit the period it’s one line of code even if spread across multiple lines in the editor" I got 4 lines of super modern, dirty, expression-style nightmare code I made just as an exercise 😀 [as opposite to my elegant solution].
If that the case, I got 3 lines of code. I don't know how my code works 🙂
Hi Thomas,
I have a doubt, in the challenge they say nothing about the use of classes that attend to solve the problem, but if I use a method that has 20 lines of code that solve the problem, 1 line of code is counted by the method call or 20 lines of code for the implementation of the method?
Well did you write the class or your reusing something supplied by the platform? But in the end I hope people aren't getting too tied up in the lines of code. I called that out mostly to challenge people to think of more inventive ways of solving the problem than just brute force approaches. Hopefully this gives you an opportunity to research some syntax that is new to you. Elegance, readability, maintainability are all factors as well. We will only use these criteria to narrow down to the finalist. Ultimately the community will vote on the winner.
I think the sentence
make the chalenge based on the number of lines.
Maybe next time, we could have "Clean Code Challenge".
The next paragraph does add to that:
Consider processing efficiency and ABAP best practices as well. How clean is your code? https://github.com/SAP/styleguides/blob/master/clean-abap/CleanABAP.md Usage of Hungarian notation will be severely ridiculed.
But point taken that people have taken to the lines of code aspect a bit more than I had personally intended. I was hoping that aspect would push people to explore some new ABAP syntax (which seeing the submissions it certainly has). Its one of several interesting aspects for people I hope. But we will be sure to balance or rotate the challenge modifiers in the future.
I'll add that I've been really impressed by how many unique and creative approaches there have been in the submissions. I think the community is going to have lots of fun looking at them once the submission period is over.
Done !
It was easier in Clean Code / more readable
So if I don't count the class/method/.. lines, I am now with 7 lines.
It is interesting to see, with the same number of lines, but with Class & methods, the code is simpler.
Do you think I could propose a Clean-Code answer if I have already send my proposal ?
Sure there was no rule against multiple submissions. Others have done so.
I've sent like 4 mails till now 😀 (Continuously every day !!)
Exactly, if there was no mention of no of lines, I sure would have not taken it as a challenge 😉
Just because of that criteria, I tried different ways and used many new functions and syntax. It sure was a fun learning experience for me 😀 ,
one of my colleague saw me doing this today and she started to learn about constructor expressions, reduce, for, e.t.c, to do this challenge.
With normal abap, surely we cannot do it in less lines, we have to use some new features to do this. maybe 2 categories would be nice, one with Clean ABAP and one with less lines. So people can push both ways.
Yes i think that the idea of Master Thomas is that we look for new ways to do it, not only using the old sentences that we are used to using. I personally have had to investigate many sentences that I did not know and I think that is the objective of the challenge, to challenge the knowledge we already have in order to be better. Thanks to Master Thomas and team.
I did it with 2 lines of code including the initial line, but one line for everything is just madness, especially the logic to count unique characters… The choice of auxiliary variable names is essential to make the code understandable. And if you do it “right” by using translatable texts, that’s even more madness ?
we need to discuss ! 😉
How could you split without split ... or how could you split & use directly the result .. ??
but have you done that using regex?
Frederic Girod Mahesh Kumar Palavalli The answer is simple: what solution other than SPLIT can you use? Of course, the issue with doing it in one statement is that fellow developers who will maintain the code need to master many aspects of the ABAP language, including the regular expressions which are widely adopted in many languages, understand very well the constructor expressions. It's often not the case, so my code fits "shortest" but doesn't fit "Elegance, readability, maintainability".
I have tried REGEX ... but ...
Bravo !!
I cannot see how it could be Clean-Coded. We do several actions in the same set of code lines.
it's not clean for sure unless we format it into multiple lines, but without the .(dot).. then it is still a single line 😛
Less lines of code is often confused with clean code. To me, clean code should be easy to read and easy to troubleshoot by anyone other than the author.
I am not agree, Clean Code is easy to maintain, it is the main objective. Check the SOLID principle.
We create more class/interfaces with sometimes design pattern. It is not easy to read.
Could I exclude the line
but pass the string as a parameter to out ?
Yes as long as you start with that string literal and be sure to still cut and paste to pickup some of the "special" conditions we created in that string.
Thanks! it will save one line and increase readability.
One "line" of code.
now working a bit on clean code... 😀
thanks for the discussion, I have it now in one line as well. I thought it might be overkill to replace the split by reduce expression. but its okay. We should compare results next time.
better late than never.
this is my result
I have to admit, that one poked at my ambitions. So here's my version of a one-liner:
Wow! That one looks really neat and elegant Jörg Wulf ! 👍
Thanks, Thomas for the challenge. Great, I didn’t know, you still do ABAP.
There is no plain text ;->
Having created the SAP Intelligent RPA Tutorials Challenge which ended Feb 29th, I totally support this very good initiative and I wish I knew ABAP programming to participate!
Kudos Thomas Jung!
Its never too late to start learning ABAP 🙂
You are definitely right: I started programming computers in 1978, being 15yo, and it was Z80 assembler, so, indeed, why not ABAP? ?
Thanks for this Thomas.
I did it with 13 lines of code with basic abap, let me cutdown number of lines.
Hi guys,
Below is my simplified version for anyone interested. A little Reduce and some regex.
Neat challenge, can't wait for the next one.
Cheers,
James
I’ve made a simple solution, using two REDUCE operations, no more than that. I believe most people went for that, or using LOOP, FOR, DO, etc., the result is the same. I thought about doing sorted tables, select, char/number calculation, or even Regex. But favored the REDUCE one. Nice to see different approaches for the same problem.
Hi,
I just found this challenge blog. Love the announcement video stream where you two comment on the submitted code! Funny reactions and comments on regex etc. Relatable 🙂
I will try get up to date with blogs and hopefully join some of the upcoming challenges.
Great challenge!
One more solution