juwaidah1990 has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; my $max = 100; my $min = 1; my @numbers = $min..$max; my $target = int(1 + rand 100); my $interval; my $guess; my $result = 3; while ($result!=1) { $interval = $max - $min; $guess = $min + int($interval/2); print "\$result = $result; \$min = $min; \$max = $max; \$interval = +$interval; \$guess = $guess\n"; $result = ✓ ($result == 0) && ($min = $guess); ($result == 2) && ($max = $guess); } sub check { print "\$guess = $guess; \$target = $target\n\n"; ($guess < $target) ? 0 : ($guess > $target) ? 2 : 1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Number gussing game
by ysth (Canon) on Jun 28, 2007 at 07:12 UTC | |
|
Re: Number gussing game
by GrandFather (Saint) on Jun 28, 2007 at 07:48 UTC | |
|
Re: Number gussing game
by davido (Cardinal) on Jun 28, 2007 at 07:17 UTC | |
|
Re: Number gussing game
by roboticus (Chancellor) on Jun 28, 2007 at 11:10 UTC | |
by juwaidah1990 (Initiate) on Jun 28, 2007 at 21:55 UTC | |
|
Re: Number gussing game
by juwaidah1990 (Initiate) on Jun 28, 2007 at 21:56 UTC | |
by GrandFather (Saint) on Jun 28, 2007 at 22:35 UTC | |
by juwaidah1990 (Initiate) on Jun 30, 2007 at 19:54 UTC | |
by GrandFather (Saint) on Jun 30, 2007 at 21:18 UTC |