Answers & Winners – Engineering Challenge (Programming Research)

We thank everyone who participated in these monthly Engineering Challenges (sponsored by PRQA). Below are the answers and winners for each month’s challenge.


October 2016

Winners:

  • Thomas Johansson (Umea, Sweden) – Amazon.com Gift Card
  • William Knight (Texas, United States) – Circuit Cellar Digital Subscription
  • Atul Undre (Pune, India) – Circuit Cellar Webshop Discount
  • David Evans (Indiana, United States) – Circuit Cellar Webshop Discount
  • Craig Bradley (California, United States) – Circuit Cellar Webshop Discount
  • Charles England (Virginia, United States) – Circuit Cellar Webshop Discount
  • Sven Lehr (Uppsala, Sweden) – Circuit Cellar Webshop Discount

Answer:

Dead Code: This is caught by our static analysis software. Line 7 Programmer initializes i to 0. Nowhere in the code does the act perform an action to change i. This creates dead code on lines 24 through 27 as i will always be 0 and the if statement will never be true.Answer October PRQA Challenge


 September 2016

Winners:

  • Bruce Burns (Oregon, United States) – Amazon.com Gift Card
  • Andreas  Hagele (Aukland, New Zealand) – Circuit Cellar Digital Subscription
  • Bob Ammerman (New York, United States) – Circuit Cellar Webshop Discount
  • Tony Vasile (New South Wales, Australia) – Circuit Cellar Webshop Discount
  • David Flores (Lima, Peru) – Circuit Cellar Webshop Discount
  • Ulises Flynn (Utah, United States) – Circuit Cellar Webshop Discount
  • Bruce Prewit (Texas, United States) – Circuit Cellar Webshop Discount

Answer:

This problem is not a logic error but a common error of omission.  This is caught by our static analysis software. Line 29 needs to be changed to :

29                      if (head != NULL)

The coder forgot to type in the exclamation point in the original line.

The  Challenge:

The following program will compile with no errors. It will crash when run. This is an example of working with link lists. The output should be:

LinkedList : 4321

LinkedList in reverse order : 1234

Click to enlarge. Find the error and submit your answer via the online submission form below. Submission deadline: 2 PM EST, September 20.

Click to enlarge


 August 2016

Winners:

  • Joffrey Carlier (Southampton, United Kingdom) – Amazon.com Gift Card
  • Guido Cargnini (Turin, Italy) – Circuit Cellar Digital Subscription
  • Jason Howard (California, United States) – Circuit Cellar Webshop Discount
  • Jan Brittenson (California, United States) – Circuit Cellar Webshop Discount
  • Sylvain Dumont (Voreppe, France) – Circuit Cellar Webshop Discount
  • Ulrich Dreher (Ditzingen, Germany) – Circuit Cellar Webshop Discount
  • Dimitris Tousis (Pella, Greece) – Circuit Cellar Webshop Discount

Answer:

This problem is not a logic error but an error in the use of the language. This is caught by our static analysis software. The problem is on line 35:

  • 35        for (d = 0; d < (n – c – 1); d++);

The “;” at the end which makes the loop empty in terms of what it is trying to do and the code on the next line starting with { will only get run once and then with the d value being the highest value.

The Challenge:

The following is a sample piece of code that has a subtle programming error that would cause the software to fail.  This code is a C++ language program but written as a function. Specification: The program does a bubble sort for a list (array) of numbers. That means that it takes a list of numbers like this: 5  23  7  1  9 and turns it into 1  5  7  9  23.

Click to enlarge. Find the error and submit your answer via the online submission form below. Submission deadline: 2 PM EST, July 20.

Click to enlarge


July 2016

Winners:

  • William Knight (Texas, USA) – Amazon.com Gift Card
  • Martin Espinosa (Washington, USA) – Circuit Cellar Digital Subscription

Answer:

This particular problem is a logic problem and not something that would be caught by static analysis.  It is a simple case of an off by one error where a loop continues too long because the logic of the “if” statement is incorrect. In this case the bounding number 1000 is not really supposed to be used, values are supposed to be “below” that value.  The result in this case is the 1000 is divisible by 5 and is included in the sum when it should not be included. The problem is on line number 20 where the check is “<=” but should just be “<”.

The Challenge:

The following is a sample piece of code that has a subtle programming error that would cause the software to fail.  This code is a C language program. Specification:

  • 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.

    Click to enlarge. Find the error and submit your answer via the online submission form.

    Click to enlarge.