Whenever storing/reading/whatever data, hash tables are highly recommended. They're fast and easy to use.
on *:text:!guess *:#:if ($hget(guess)) && ($2 isnum) hadd guess $nick $2
on *:text:!result *:#: {
if ($nick !isop #) noop
elseif ($2 !isnum) .notice $nick Invalid input. Use as: !result <number>
else {
var %x = 1,%a $2,%b 99999999,%n n/a n/a
while ($hget(guess,%x).item) {
tokenize 32 $v1 $hget(guess,$v1)
if ($abs($calc($2 -%a)) < %b) var %b = $v1,%n $1 $2
inc %x
}
tokenize 32 %b %n
.notice $nick Closest guess was $qt($3) by $2 (Difference: $1 $+ )
}
}
on *:text:!start:#:if ($nick isop #) hfree -w guess | hmake guess | .notice $nick Started!
on *:text:!stop:#:if ($nick isop #) hfree -w guess | .notice $nick Stopped!
No idea how admins are identified, but currently only operators can use the !result, !start and !stop commands.
"!start" starts the thing, "!stop" stops it and "!result <number>" gives you the best answer.