🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #3668

Re: Towers of Hanoi

#3668
From: Dick Snippe
Date: Mon, 07 Aug 1995 08:31
36 lines
1531 bytes
In <1995Aug6.155559.56140@msuvx2.memphis.edu> bsimpson@stim.tec.tn.us (Brady Simpson) writes:

>HELP!!

>I have been looking everywhere for a source code in c for the puzzle "Towers 
>of Hanoi". Does anyone know where I might possibly get the source code for 
>this puzzle. If so, would you mind e-mailing the information to 
>bsimpson@stim.tec.tn.us.

Why would you be looking for the source code, if the program is so trivial that
you can write it yourself? Here 't is: (warning: untested code follows; it
may erase your harddisk :-) 
--------cut here-------
#include <stdlib.h>
#include <stdio.h>

/* move n discs from x to y with the help op h */
void hanoi(char *x, char *y, char *h, int n)
{
  if (n>0)
  {
    hanoi(x,h,y,n-1);
    printf("%s -> %s\n",x,y);
    hanoi(h,y,x,n-1);
  }
}

int main(int argc, char *argv[])
{
  hanoi("a","b","c", (argc==2) ? atoi(argv[1]) : 64 /* :-) */ );
  return 0;
}
--------cut here-------
--
Dick Snippe (dick@mi.el.utwente.nl) (+31 53 892785)   \  Fight war,
University of Twente, Lab. meettechniek&instrumentatie \  not wars.
Technical Details
Message-ID: <404j05$3ul@driene.student.utwente.nl>
Path: arc1-ca.pugleaf.net!news.nic.utwente.nl!dick
References: <1995Aug6.155559.56140@msuvx2.memphis.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.nic.utwente.nl!dick
From: dick@utelmi01.el.utwente.nl (Dick Snippe)
Newsgroups: comp.std.c
Subject: Re: Towers of Hanoi
Date: 7 Aug 1995 08:31:01 GMT
Organization: University of Twente, Enschede, The Netherlands
Message-ID: <404j05$3ul@driene.student.utwente.nl>
References: <1995Aug6.155559.56140@msuvx2.memphis.edu>
NNTP-Posting-Host: utelmi01.el.utwente.nl
X-Newsreader: NN version 6.5.0 #12 (NOV)