Slidding puzzle in Ocaml


Hello everyone,

In order to familiarize myself with the Ocaml language for the pursuit of my studies, I set myself the goal of creating a sliding puzzle that will be in Ocaml.
Why sliding puzzle ? I fell back on old subjects from my university and one of them was:

"Make random moves on a sliding puzzle, then solve it by
program (and without cheating). Up to what size of sliding puzzle can you go before that your program is getting too slow?

Note: The Ocaml graphics.cma library is more than enough. "

The problem :
I do not see how to start or how to implement this, so I ask for your help.

Thank you in advance.


The excellent book by Cousineau and Mauny covers this very problem in its “red donkey” variant, if I recall correctly. This book is IMHO one of the must-reads for OCaml (it was initially written for its Caml Light ancestor but little has changed when it comes to learning functional style basic data structuring and programming).


For the Taquin puzzle here is a link:

(written in Caml-light…)


The repository containing the programs that are used in the (Cousineau and Mauny) book is here now:

HINT: For people struggling with the Project 1 of the MOOC:

L’Ane Rouge (The Red Donkey) is an another name for Klotski.


Thanks a lot, I’ll watch this all during the next week, I have a lot of work this week-end :hugs: