Any Easy Solution to the Hands of Time Clock Puzzles?

There are a few hands of time solvers out there.

Personally i find these the best:

http://clockpuzzle.pl/ (its online so nothing to download)

or

http://www.mediafire.com/?dar4yh69lxcaavh


Doing it manually, I've found the best way to get a correct solution is to look at each number on the board, and mark which numbers it can be the next in the chain. Rather than continue the chain, I move onto the next number clockwise, until I've built a table of values. That table is usually enough to figure out the correct chain.

So, for example, take the following clock:

  2
2   2
3   1
  1

Assigning a letter to each number starting with the 2 at the top and working my way clockwise, I can generate a table like this:

    A | B | C | D | E | F
--------------------------
A   x | x | o | x | o | x
B   o | x | o | x | x | x
C   x | o | x | o | x | x
D   x | o | x | x | x | o
E   x | o | x | x | x | x
F   x | o | x | o | x | x

From this, I can see that E must lead into B. By eliminating other choices as they become locked in the chain, I can arrive at the correct solution, which is:

AEBCDF

This scales to any size clock, but it's tedious. So instead, I decided to write an automated solution in PHP:

<?php

// Supply clock values clockwise.
// Keys can be anything you want to use to remember the positions.
$clock = array(
  'a' => 2,
  'b' => 1,
  'c' => 1,
  'd' => 2,
  'e' => 3,
  'f' => 2,
);

$positions = array_keys($clock);
$values = array_values($clock);

// Test all possible starting positions.
for ($i = 0; $i < count($clock); ++$i) {
  $chain = test_clock($values, $i);

  // When the solution has all values, it's the right one.
  if (count($chain) == count($clock)) {
    break;
  }
}

// Use the user-supplied keys.
$solution = array();
foreach ($chain as $position) {
  $solution[] = $positions[$position];
}

print 'The solution is: ' . implode($solution, ' → ') . PHP_EOL;

/**
 * Recursively test the clock based on a supplied position.
 *
 * @param array $values
 *   The current values of the clock.
 * @param integer $i
 *   The current position of the clock.
 * @param array $chain
 *   The current possible solution.
 *
 * @return
 *   An array of positions that represents a possible solution.
 */
function test_clock(array $values, $i, array $chain = array()) {
  // If the value of the position we're in is 0, we've already tested it.
  if ($values[$i] == 0) {
    return $chain;
  }

  // Find the next two positions.
  $position1 = $i + $values[$i];
  $position2 = $i - $values[$i];

  // Account for wraparound in the array.
  if ($position1 > count($values) - 1) {
    $position1 -= count($values);
  }
  if ($position2 < 0) {
    $position2 += count($values);
  }

  // Mark this position as tested.
  $values[$i] = 0;
  $chain[] = $i;

  // Test the first position.
  $solution = test_clock($values, $position1, $chain);

  // Don't bother checking the second position if the first is correct.
  if (count($solution) == count($values)) {
    return $solution;
  }

  // Test the second position.
  return test_clock($values, $position2, $chain);
}

Drop that into a file, let's say hands-of-time.php, and run it either off of a webserver or via PHP CLI:

$ php hands-of-time.php
The solution is: a → e → b → c → d → f

Change the $clock array to whatever the puzzle is. For example, here's one of the larger clocks:

$clock = array(
  'a' => 2,
  'b' => 2,
  'c' => 2,
  'd' => 4,
  'e' => 2,
  'f' => 2,
  'g' => 3,
  'h' => 3,
  'i' => 6,
  'j' => 4,
  'k' => 5,
  'l' => 3,
);

And here's the output:

The solution is: a → k → f → h → e → g → j → b → d → l → i → c