Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!mach1!torn!cs.utexas.edu!swrinde!emory!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Tower of Hanoi & Grey Code was "j combinations"
Message-ID: <1993Feb25.113513.26077@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
Date: Thu, 25 Feb 1993 11:35:13 GMT
Lines: 63


Summary of "j combinations" e-mail:

Raul Rockwell suggested the following verb to translate
binary representation to grey:

bin_to_grey =. (2&(~:/\))@(0&,)

So one would type

bin_to_grey"1 #: i. 16

<>
Mr. Silva brought to my attention that there is a relationship
depict in the tutorial in the "Dictionary of J" and the Grey Code
representation of binary digits and the Towers of Hanoi.
I figured out what it is.

For the binary representation below with the ones summed :

+-------+-+
|0 0 0 0|0|
|0 0 0 1|1|
|0 0 1 1|2|
|0 0 1 0|1|
|0 1 1 0|2|
|0 1 1 1|3|
|0 1 0 1|2|
|0 1 0 0|1|
|1 1 0 0|2|
|1 1 0 1|3|
|1 1 1 1|4|
|1 1 1 0|3|
|1 0 1 0|2|
|1 0 1 1|3|
|1 0 0 1|2|
|1 0 0 0|1|
+-------+-+

The corresponding TOH model has 4 disks and the disk number of the
moving disk is equal to the sum of the ones. So the first three
moves are :


  1      
  2        ->  2         ->            ->
  3            3             3            3  1*
  4  _  _      4   _  1*     4  2*  1     4  2  _
  

Then Lee Dickey wrote:
   
> These things are great for analog to digital converts for
> rotary motion.  Two other context that are closely related are
> Hamiltonian paths on the n-cube (visit every vertex, move along the
> 1-skeleton), and Chinese rings, which give rise to sequences like
>    1 2 1 3 1 2 1 4 1 2 1 3 1 2 1 5 ...
> which tell which coordinate (right to left) to change from 0 to 1 or
> 1 to 0.

  Fun.

  Emmett
