Keep It Simple, Stupid PerlMonks

### ObJAPH

by jima (Vicar)
 on Oct 27, 2000 at 19:38 UTC Need Help??

```%M = (
A, sub { return                   \$_[0] ** 2 -  22 * \$_[0] +   8
+5 },
B, sub { return                   \$_[0] ** 2 +   9 * \$_[0] +   2
+0 },
C, sub { return                   \$_[0] ** 2 -  16 * \$_[0] -   3
+6 },
D, sub { return \$_[0] ** 3 - 15 * \$_[0] ** 2 - 400 * \$_[0] - 150
+0 },
E, sub { return \$_[0] ** 3 - 43 * \$_[0] ** 2 + 590 * \$_[0] - 260
+0 },
F, sub { return                   \$_[0] ** 2 -  19 * \$_[0] -  15
+0 },
G, sub { return \$_[0] ** 3 - 98 * \$_[0] ** 2 - 199 * \$_[0] -  10
+0 },
H, sub { return                   \$_[0] ** 2 -  25 * \$_[0] +  14
+4 },
I, sub { return                   \$_[0] ** 2 +  47 * \$_[0] -  19
+0 },
J, sub { return                   \$_[0] ** 2 +  22 * \$_[0] -   2
+3 },
K, sub { return                   \$_[0] ** 2 +  23 * \$_[0] -  79
+8 },
L, sub { return                   \$_[0] ** 2 -  13 * \$_[0] -   3
+0 },
M, sub { return                   \$_[0] ** 2 +  37 * \$_[0] -  19
+0 },
N, sub { return                   \$_[0] ** 2 -   1 * \$_[0] -   3
+0 },
O, sub { return                   \$_[0] ** 2 -   4 * \$_[0] -   2
+1 },
P, sub { return                   \$_[0] ** 2 -  11 * \$_[0] -   1
+2 },
Q, sub { return \$_[0] ** 3 - 12 * \$_[0] ** 2 + 379 * \$_[0] - 515
+6 },
R, sub { return \$_[0] ** 3 - 46 * \$_[0] ** 2 + 679 * \$_[0] - 323
+4 },
S, sub { return                   \$_[0] ** 2 +  44 * \$_[0] -  14
+1 },
T, sub { return                   \$_[0] ** 2 -  12 * \$_[0] +   3
+2 },
U, sub { return                   \$_[0] ** 2 +   9 * \$_[0] -   2
+2 },
V, sub { return                   \$_[0] ** 2 +  14 * \$_[0] +   3
+3 },
W, sub { return                   \$_[0] ** 2 +  37 * \$_[0] -   1
+2 },
X, sub { return \$_[0] ** 3 + 11 * \$_[0] ** 2 + 135 * \$_[0] -  14
+2 },
Y, sub { return                   \$_[0] ** 2 -  59 * \$_[0] -   1
+4 },
Z, sub { return                   \$_[0] ** 2 +  20 * \$_[0] +   6
+4 }
);

\$DELTA = 0.045;
\$RANGE_LO = 0;
\$RANGE_HI = 100;

sub binsearch {
my(\$key, \$lo, \$hi) = @_;
my(\$mid) = \$lo + (\$RANGE_HI - \$hi) / \$RANGE_HI;

++\$mid;
if (\$lo/\$mid + \$DELTA <= 1.0) {
if (&{\$M{\$key}}(\$mid) > 0) {
return binsearch(\$key, \$mid, \$hi);
} elsif (&{\$M{\$key}}(\$mid) < 0) {
return binsearch(\$key, \$lo + 1, \$hi);
} else {
\$RESULT[\$mid]  = (\$mid**2 - 13*\$mid + 12 ? lc \$key : \$key)
+;
\$RESULT[\$mid] .= ' ' if !(\$mid**3 - 30*\$mid**2 + 269*\$mid
+- 660);

return binsearch(\$key, \$mid, \$hi);
}
} else {
return 0;
}
}

foreach (keys %M) { # find roots of each equation in range
binsearch(\$_, \$RANGE_LO, \$RANGE_HI);
}

print @RESULT;
print ",\n"; # for canonical JAPH form

Create A New User
Node Status?
node history
Node Type: obfuscated [id://38835]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-04-20 19:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My travels bear the most uncanny semblance to ...

Results (78 votes). Check out past polls.

Notices?