they have a programming exercise here at the website like this, and the solution:
exercise:
http://www.cprogramming.com/challenges/permute.html
solution
http://www.cprogramming.com/challenges/permutesol.html

it is in c++ but can be easily converted.