So, I saw on SlashDot (http://www.slashdot.org/) a story about a guy who has over 100 
different implementations of the Towers of Hanoi solution, each in a different 
language.  Since he didn't have one in PL/SQL, I decided to write one.  

Here it is:
create or replace package hanoi
is
from_peg  constant number := 1;
to_peg    constant number := 3;
using_peg constant number := 2;

procedure play(n number);

end hanoi;
/
create or replace package body hanoi
is

procedure do_hanoi(n number, from_peg number, to_peg number, using_peg number)
is
begin
    if(n > 0) then
        do_hanoi(n-1,from_peg, using_peg, to_peg);
        dbms_output.put_line('move '||from_peg||' --> '||to_peg);
        do_hanoi(n-1, using_peg, to_peg, from_peg);
    end if;
end;
procedure play(n number)
is
begin
    do_hanoi(n, from_peg, to_peg, using_peg);
end;
end;
/

This concludes this public service announcement.  We now return you to our regularly 
scheduled programming.

-Mark

PS  Yes, it's a slow day....;-)
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Bobak, Mark
  INET: [EMAIL PROTECTED]

Fat City Network Services    -- 858-538-5051 http://www.fatcity.com
San Diego, California        -- Mailing list and web hosting services
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

Reply via email to