Life So Short, the Craft So Long to Learn

Twenty-Four Puzzle OCaml iOS App

February 18, 2016

I wrote the Slide24 app a few years ago as a semi-credible example of an iOS app coded in OCaml. It implements the 24 puzzle, a 5 × 5 grid of sliding numbered tiles. I enjoyed the physical version of the puzzle tremendously as a kid.

I just now updated Slide24 to build under Xcode 7.2, and tested that it works under iOS 9.2 on every iPhone and iPad device (simulating the ones I can’t find in real life).

image of Slide24 app

Slide24 has a Solve button that solves the puzzle for you if you don’t have the inclination to do it yourself. While I was updating the rest of the code, I rewrote the heuristic search to generate solutions that are more interesting to watch as a spectator. The essence of the improvement is that the search now gets a pretty good (not optimal) solution, but is able to solve the whole puzzle at once. I’m thankful to Dr. Wheeler Ruml of the University of New Hampshire for suggestions along these lines.

The new search doesn’t quite reach the level of unbelievable perfection that I was seeking, but it does produce solutions that don’t look anything like what a person would do. When I solve the puzzle I tend to work on one area at a time, while the heuristic solution makes small changes all over the place. Then things come together surprisingly quickly at the end, which is just what I was hoping to see.

If you just want to download Slide24 and build it in Xcode, you can get the sources here:

Slide24 3.0.4, tested on iOS 9.2

I’ve also written out some instructions and principles of operation here:

Slide24: Sliding Tile Puzzle for iOS

If you have any comments, suggestions, or encouragement, leave them below or email me at

Posted by: Jeffrey


blog comments powered by Disqus