A multi-paradigm solution for an ancient puzzle
Joel A. Rosiene, Carolyn Pe Rosiene · Journal of computing sciences in colleges · 2014
This paper presents alternate and nifty illustrations to programming, both using traditional programming languages and using a description language for the nine linked rings - an ancient Chinese puzzle and perhaps China's greatest mechanical puzzle. Played by royalty and peasants alike in ancient China, the nine linked rings puzzle consists of a looped handle and nine interlocking rings. Each ring is locked to the ring before it. The goal is to remove all nine rings from the puzzle's handle. The basic premise to the solution is - to remove a ring, the ring before it must be the lead ring. In order to make any ring a lead ring, all other in front of it must be removed. The puzzle is intrinsically recursive and therefore dovetails with a recursive solution. However, a declarative solution using the logic paradigm also demonstrates the strength and expressiveness of the paradigm. A third solution is presented using a synthesized and somewhat unnatural iterative to solve the puzzle. And ultimately, a description language, VHDL, is used to demonstrate the fourth approach. Unlike traditional development which assumes an underlying machine architecture, this approach is based on custom finite state machine. This approach is most similar to the logic based solution, with the horn clauses replaced with partially constrained, next state logic. The synthesis of the then solves the problem, and produces the hardware which enumerates steps in the procedure. The nine rings puzzle is well suited to demonstrating algorithm as hardware. Since the solution to the problem is easily demonstrated in each of the programming paradigms, it is a useful tool to illustrate the differences in approach when using custom versus a processor. Although inherently recursive, the puzzle provides a foundation to form several algorithms and solutions using a variety of programming models. The nine linked rings puzzle is yet another great example of taking an ancient puzzle and applying modern day algorithmic approaches to express computations in a variety of approaches.