## Problem:

If A[N] is array of N integers. Shuffle the elements of A in such way that the differences between each neighbour elements d[i] = A[i]-A[i+1] make row in ascending order.

For instance:

A[4] = { 10, 2, 7, 4 }

possible soluions are:

{  2, 7, 10, 4 } because  (2 – 7) < (7 – 10) < (10 – 4)

or:

{ 4, 10, 7, 2 } because (4 – 10) < (10 – 7) < (7 – 2)

## The rules

You can code the solution in any language during the weekend and have to submit it to info@olimex.com latest on Sunday March 31th .

On Monday we will upload the solutions on GitHub and review https://github.com/OLIMEX/WPC .

You can play with your real name or with nick if you want to be anonymous, we will not disclosure your personal info if you do not want to.

1. ? this is just bubble sort or any of its versions.. Isn’t there supposed to be a rule to make it as fast as possible or the code as short as possible?

Rgds,

Rene

• how do you do bubble sort when each two element swap change the surounding elements differences?

2. Reblogged this on ngalia.

3. it is challenging if you are trying to see it as expandable…. more than 4 have anyone tried this? 10 18 7 45 20

4. How do I send my solution?

• read the post 🙂 Rules

5. I wish I’d had time to enter this weekend – I’d like to think that I’d have used Dijkstra’s algorithm, but I’m not sure that I would have!

6. Trackback: Weekend Programming Challenge Issue #2 Late Entry | olimex