Skip to main content
deleted 47 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

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.

Tcl, 122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {};puts =

Ok, and now guessing a real number (110 chars):

proc 1 {} return\ 1;set n [expr rand()*100+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {}

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.

Tcl, 96 chars

set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n} {puts [expr $g<$n?"+":"-"]};puts =

Ok, and now guessing a real number (91 chars):

set n [expr rand()*100+1];while {[gets stdin g]&&$g!=$n} {puts [expr $g<$n?"+":"-"]};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.

added 581 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

Tcl, 122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {};puts =

Ok, and now guessing a real number (110 chars):

proc 1 {} return\ 1;set n [expr rand()*100+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {}

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.

Tcl, 122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {};puts =

Tcl, 122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {};puts =

Ok, and now guessing a real number (110 chars):

proc 1 {} return\ 1;set n [expr rand()*100+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {}

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.

deleted 1 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44

Tcl, 123122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n ?[puts +;1]:[puts -;1])} {};puts =

Tcl, 123 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n ?[puts +;1]:[puts -;1])} {};puts =

Tcl, 122 chars

proc 1 {} return\ 1;set n [expr int(rand()*100)+1];while {[gets stdin g]&&$g!=$n&&($g<$n?[puts +;1]:[puts -;1])} {};puts =
deleted 3 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44
Loading
added 7 characters in body
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44
Loading
Source Link
Johannes Kuhn
  • 7.5k
  • 5
  • 32
  • 44
Loading