# SAP Community Coding Challenge 2 – Contestants

Here’s a list of the SAP Community Coding Challenge 2 contestants who were successful in their submissions. Congratulations to them all!

Following the update blog post and the live stream last week (recording here) I thought it was time for a main list of successful contestants.

The current SAP Community Coding Challenge has seen a wonderful array of submissions, and for that we thank you all. Over the course of the submission period we received 79 in total, with a success rate (i.e. where the submission produced the correct answer) was over 90%, which is great.

Styles

We saw all kinds of styles, from beginner JavaScript coders to advanced, some opting for a class based approach, others for a more functional one. With a language as flexible as JavaScript it was clear that we were going to see folks’ personalities in places too … from the use of whitespace, to how variables and functions were named and capitalised, to how commenting was used to good effect (or, in some cases, how no comments were used at all).

Speed

Another factor that came up was how performant the submissions were. Although speed was not a factor explicitly stated in the original post, it was clear that many of you enjoyed making your submissions run as fast as possible, and so we saw a number of common optimisations. The most common was a cache of the sequence lengths for a given starting term, so that when working through a sequence, if the term arrived at was one already seen, that sequence could be short-circuited there and then by adding the length thus far to the length for that term.

There were also more subtle optimisations, such as the use of the bitwise operator to check for an odd number, which did give a very slight but ultimately perceptible speed advantage at the scale of the problem. Commonly, checking for an odd (or even) number is done using modulo arithmetic, like this:

``isOdd = x => x % 2 !== 0``

(i.e. x is odd if the remainder of x / 2 is not zero)

But there’s the bitwise AND operator that was used by some:

``isOdd = x => x & 1``

(i.e. x is odd if x, when AND-ed with 1 (binary 00000001) gives a non-zero value (i.e. 1))

Use of libraries

For the most part, the submissions were independent of any external (3rd party) library. JavaScript, esp. in the Node.js flavour, has a cornucopia of libraries that can be used to good effect (although sometimes this is not so much the case, but that’s a story for another time!)

We did see a small amount of library use, for example the mathjs library (which offers a max function, amongst other things), yosay, for making output a little more fun, and Ramda, a functional programming library offering a rich set of functions. Indeed, we had one or two submissions that were “Ramda-oriented”, which delighted me no end.

Lack of range

One thing that was clear, and common, was that many of you came across the issue that there’s no native ‘range‘ function in JavaScript – to generate a range of numbers in a simple way. Of course, there’s the more procedural ‘for loop’ approach, but for those wanting to level up and move away from telling the machine how to do something it should already know, you came up with a lovely, err, array of approaches. See if you can spot them all in the submissions.

Out of bounds

There were a couple of submission that didn’t quite conform to the submission requirements but we thought they were fun and creative nonetheless (and accompanied a proper submission, which made things OK :-)).

There were also some submissions that sadly didn’t produce the correct result; the most common issue was a focus on the initial example in the problem statement, rather than the question itself.

The submissions

So without further ado, here is the complete list (in no particular order) of successful submissions. Take a look at your fellow community members’ submissions and see how they coded their solutions – I for one really enjoyed studying all of them. There are some really thoughtful and educational pieces in this collection. Thank you all.

Congratulations to everyone!

Check out the recording of last week’s live stream for a look at some of these.

Next steps

So now we have all the successful submissions listed here, we’ll be posting an entry into the Community Q&A area later this week with a shortlist of finalists, for you to vote on as the overall winner. Stay tuned!

Appendix – Performance testing

For those interested, I loaded all the submissions that I could into a local project, and ran them through a little script to get a rough idea of the throughput. For some of the submissions that presented the output in HTML, I had to make minor modifications to allow them to be executed directly in Node.js at the command line, but other than that, I ran the scripts unaltered.

I used hyperfine, a command line benchmarking tool, which worked really well for me. I wrapped it in a script for convenience. Here’s a screenshot of the tool in action — showing an entry that was outside of the allowed submissions — and the wrapper script itself. Share & enjoy!

``````#!/usr/bin/env bash

# Performance tests
# Run as either 'perftest' (and pick a submission) or 'perftestall' (via the symlink) to process all of them.
# Uses 'hyperfine' with a single run as warmup, and the average taken from 10 (the default) runs.

subdir=submissions

heading() { figlet -w \$(tput cols) \$@ | lolcat; }
pick() { ls -1 \${subdir} | fzf; }

if [ \$(basename \$0) = "perftestall" ]
then
candidatelist=\$(ls -1 \${subdir})
else
candidatelist=\${1:-\$(pick)}
fi

for sub in \${candidatelist}
do
&& hyperfine --time-unit millisecond --warmup 1 "node \${subdir}/\${sub}/index"
done``````

Related blogs