Tcl, 12296 chars
proc 1 {} return\ 1;setset n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&(=$n} {puts [expr $g<$n?[puts +;1]"+":[puts "-;1])} {"]};puts =
Ok, and now guessing a real number (11091 chars):
proc 1 {} return\ 1;setset n [expr rand()*100+1];while {[gets stdin g]&&$g!=$n&&(=$n} {puts [expr $g<$n?[puts +;1]"+":[puts "-;1])"]};puts {}=
And here a small script to test this: (Solver)
set fd [open "| /usr/local/bin/tclsh hilo.tcl" RDWR]
fconfigure $fd -buffering none
lassign 0\ 100 + -
while 1 {
puts "-> [set new [expr {(${-} - ${+}) / 2. + ${+}}]]"
puts $fd $new
gets $fd in
puts "<- $in"
if {$in in {+ -}} {set $in $new} break
}
Change the 2.
to 2
for integers.