Skip to content

Instantly share code, notes, and snippets.

@bjmllr
bjmllr / triangle_peg.rb
Last active June 14, 2016 01:06 — forked from bokmann/triangle_peg.rb
An example from "What Computer Scientists Know: Thinking Recursively, Part 2. In this example we are going to explore how we use our newfound knowledge of recursion to search through all the solutions of a simple puzzle using recursive backtracking.
POSSIBLE_MOVES = [[3,4,5], [5,4,3],
[6,7,8], [8,7,6],
[7,8,9], [9,8,7],
[10,11,12], [12,11,10],
[11,12,13], [13,12,11],
[12,13,14], [14,13,12],
[0,1,3], [4,1,0],
[1,3,6], [6,3,1],
[3,6,10], [10,6,3],
[2,4,7], [7,4,2],