Do you know where your variables are? PerlMonks

### comment on

 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

In reply to ObJAPH by jima

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

• Are you posting in the right place? Check out Where do I post X? to know for sure.
• Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
• Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
• Want more info? How to link or How to display code and escape characters are good places to start.

Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2022-12-07 13:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?