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.
Rene
Mar 30, 2013 @ 12:27:17
? 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
OLIMEX Ltd
Mar 30, 2013 @ 22:01:09
how do you do bubble sort when each two element swap change the surounding elements differences?
ngalia
Mar 30, 2013 @ 15:26:25
Reblogged this on ngalia.
Kristian Josef Delos Reyes
Mar 31, 2013 @ 07:46:22
it is challenging if you are trying to see it as expandable…. more than 4 have anyone tried this? 10 18 7 45 20
Kristian Josef Delos Reyes
Mar 31, 2013 @ 07:58:23
How do I send my solution?
OLIMEX Ltd
Mar 31, 2013 @ 09:52:14
read the post 🙂 Rules
Iain Cunningham (@IainIsm)
Apr 02, 2013 @ 00:28:10
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!