# New Ticket Created by  "Senaka Fernando" 
# Please include the string:  [perl #52888]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=52888 >


Hi all,

I would like to make two improvements to the towers of hanoi sample.

1. Use default tower size if an invalid value is provided.
2. Print initial arrangement of towers at start

No. 2, is not a requirement (says pmichaud), so the respective code is
commented out.

Regards,
Senaka
Index: examples/pir/hanoi.pir
===================================================================
--- examples/pir/hanoi.pir	(revision 26966)
+++ examples/pir/hanoi.pir	(working copy)
@@ -108,10 +108,14 @@
         if $I0 < 2 goto USE_DEFAULT_SIZE
         S5 = argv[1]
         size = S5
+        if size < 1 goto INVALID_SIZE
         print "Building a tower of size "
         print size
         print ".\n"
         goto SIZE_IS_NOW_KNOWN
+INVALID_SIZE:
+        print "Given tower size is invalid.\n"
+        goto USE_DEFAULT_SIZE
 USE_DEFAULT_SIZE:
         print "Using default size 3 for tower.\n"
         size = 3
@@ -140,8 +144,12 @@
         if i > 0 goto loop_populate
         ## towers = [[...,3,2,1],[],[]]
 
+        # uncomment to print initial layout
+        # print_towers(towers)
+
         ## Now solve it.
         move_stack(size, 0, 2, 1)
+        .return ()
 .end
 
 ## Print the current state of the towers array.

Reply via email to