WEEKEND PROGRAMMING CHALLENGE ISSUE #2 RESULTS


For these who do not follow the challenge the problem for solution this weekend was to sort array by the differences between neighbor elements, although it looks simple the catch is that every time you swap two components you change the differences between them and their neighbors as well.

The Easter Holidays probably messed up this challenge as we got only 6 Solutions.

The solutions are uploaded to GitHub: https://github.com/OLIMEX/WPC

Number of languages used: 4

Ruby, C, Python, Prolog

The interpreters I used to evaluate the solutions:

Ruby – http://kidsruby.com/

Python – http://python.org/ (2.7)

C – http://www.codeblocks.org/ (GCC)

Prolog – http://www.probp.com/download.html

Prolog solution and installation is most exoting so I give you here the instructions from Piotr:

download and install b-prolog then execute bp.bat or bp.sh, you will see command prompt

?-

to load the code write:

?- consult(olimex)

?- go

then you can call the sorting with

?- shu([10,2,7,4])

2  7 10  4
4 10  7  2

or:

?- shu([10,2,7,4,11])
2  7 10 11  4
2  7 11 10  4
4 10 11  7  2
4 11 10  7  2

if there is no solution like:

?- shu([10,18,7,45,20])

the program prints:

no

Solutions 2, 5 and 6 receive our applaudes!

1 Comment (+add yours?)

  1. Iain Cunningham (@IainIsm)
    Apr 01, 2013 @ 23:55:03

    Easter certainly caused me a hiccup!

    Really like use of the Dijkstra algorithm in the solutions. Also Prolog – another new language to look at 🙂

    Reply

Leave a comment