💾 Archived View for runjimmyrunrunyoufuckerrun.com › rc › guess captured on 2021-12-17 at 13:26:06.

View Raw

More Information

-=-=-=-=-=-=-

#!/bin/rc
rfork e
switch($#*){
case 2
	from = $1
	to = $2
case 1
	from = 1
	to = $1
case 0
	from = 1
	to = 100
case *
	echo usage: $0 '[[from] to]' >[1=2]
	exit usage
}
if(! test $from -lt $to){
	echo bad guessing range: from $from to $to >[1=2]
	exit 'bad range'
}
n = `{fortune <{seq $from $to}}
r = `{seq $from $to | grep -v '^'$n'


}
fn sighup sigint sigkill{
	echo answer was $n
	exit 'gave up'
}
echo guess my number!
while(g = `{read}){
	if(~ $n $g){
		echo you got it!
		exit
	}
	if(~ $g '' || ~ $g *[~-0-9]* || ! test $from -le $g -a $g -le $to)
		echo number is between $from and $to
	if not if(test $g -lt $n) echo higher!
	if not if(test $g -gt $n) echo lower!
}
echo
sighup