Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

2Re: Worst thing you ever made with Perl

by jeffa (Chancellor)
on Sep 28, 2003 at 23:29 UTC ( #294829=note: print w/ replies, xml ) Need Help??


in reply to Re: Worst thing you ever made with Perl
in thread Worst thing you ever made with Perl

And now, the re-write:

use strict; use warnings; use CGI qw(header param); use HTML::Template; my @solution; my $tmpl = HTML::Template->new(filehandle => \*DATA); if (param('go')) { my $discs = param('discs'); $discs = 1 if $discs < 1 or $discs > 15; hanoi($discs,'A','B','C'); $tmpl->param( solution => \@solution, discs => $discs, ); } print header, $tmpl->output; # original algorithm learned from Brenda Parker sub hanoi { my ($number, $from, $to, $aux) = @_; if ($number == 1) { push @solution, {step => "Move 1 from $from to $to"}; } elsif ($number != 0) { hanoi($number-1,$from,$aux,$to); push @solution, {step => "Move $number from $from to $to"}; hanoi($number-1,$aux,$to,$from); } } __DATA__ <html> <head> <title>Towers of Hanoi</title> </head> <body> <form> <p> Enter number of discs desired (15 is MAX): <input type="text" name="discs" size="2" /> </p> <input type="submit" name="go" value="Solve" /> </form> <tmpl_if solution> <hr/> Solving for <tmpl_var discs> discs: <ol> <tmpl_loop solution> <li><tmpl_var step></li> </tmpl_loop> </ol> </tmpl_if> </body> </html>

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on 2Re: Worst thing you ever made with Perl
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://294829]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2014-11-23 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (131 votes), past polls