Guess the number/With feedback (player): Difference between revisions

(Added FreeBASIC)
(→‎{{header|XPL0}}: added zkl)
Line 2,967:
Is it 17 (Y = yes, H = too high, L = too low)? Y
Yippee!
</pre>
 
=={{header|zkl}}==
Your basic binary search.
<lang zkl>println("Pick a number between 0 and 100 and remember it.");
low,high,g := 0,100, 20;
while(True){
r:=ask("I guess %d; is that high, low or =? ".fmt(g)).strip().toLower();
if(r=="="){ println("Yea!"); break; }
if(r[0]=="h") high=g-1 else low=g+1;
if(low==high){ println("Yea! the number is ",low); break; }
if(low>high){ println("I'm confused!"); break; }
g=(low + high)/2;
}</lang>
{{out}}
<pre>
Pick a number between 0 and 100 and remember it.
I guess 20; is that high, low or =? l
I guess 60; is that high, low or =? h
I guess 40; is that high, low or =? h
I guess 30; is that high, low or =? h
I guess 25; is that high, low or =? l
I guess 27; is that high, low or =? h
Yea! the number is 26
</pre>
 
Anonymous user