#!/usr/bin/perl -wT use strict; my $low = 0; my $high = 40000; # guesses integet between two other integers my $ans = ''; while ($ans ne 'C') { my $mid=int (($low+$high)/2); print "is $mid low, high or correct? :"; $ans=<STDIN>; $ans=uc(substr($ans,0,1)); if('L' eq $ans){ $low = $mid+1; }elsif('H' eq $ans){ $high = $mid-1; }elsif($ans ne 'C') { print "bad input\n"; } } print "thank you for playing\n";
-Blake
In reply to Re: bushy recursion a good thing ?
by blakem
in thread bushy recursion a good thing ?
by mandog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |