Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Merely an unscientific toy that tries to tell if you're a risk-taker or not. Run the script and answer a few questions at the prompt.
use strict; use warnings; my $input = input(); print $input->(0); while(<STDIN>){ my $output = $input->($_); last unless $output; print $output; } sub input { my @policy; my @damage = qw/ 0 33.21 57.36 72.45 138.87 253.59 298.88 /; my($text,@prompt,@result); while (<DATA>) { if(/TEXT1/../TEXT2/){$text .= $_ unless /[A-Z]+[12]/} if(/PROMPT1/../PROMPT2/){chomp; push @prompt, $_ unless /[A-Z] ++[12]/} if(/RESULT1/../RESULT2/){chomp; push @result, $_ unless /[A-Z] ++[12]/} } print $text; return sub { push @policy, shift; return $#policy < 6 ? $prompt[$#policy] : $#policy == 6 ? predict(\@damage,\@policy,\@result) : unde +f; }; } sub predict { my $slope = slope(shift, shift); my @r = @{$_[0]}; if ($slope < 0.625) { return "\n " . $r[0] . percent($slope); } elsif ($slope < 0.8) { return "\n " . $r[1] . percent($slope); } elsif ($slope < 1.25) { return "\n " . $r[2] . percent($slope); } elsif ($slope < 1.6) { return "\n " . $r[3] . percent($slope); } else { return "\n " . $r[4] . percent($slope); } } sub percent { if ($_[0] < 0.8) { return "\n You're paying " . int(100*(1-$_[0])) . "% less +than you should.\n"; } elsif ($_[0] > 1.25) { return "\n You're paying " . int(100*($_[0]-1)) . "% more +than you should.\n"; } else { return "\n You're paying " . int(100*$_[0]) . "% of the \" +right\" price.\n"; } } sub sum {my $sum = 0; $sum += $_ for @_; $sum} sub mean {sum(@_)/scalar(@_)} sub sumn { my($n, $mean) = (shift, mean(@_)); sum(map{($_ - $mean)**$n} @_); } sub sumxy { my @x = @{$_[0]}; my @y = @{$_[1]}; return unless $#x == $#y; my ($xmean, $ymean) = (mean(@x), mean(@y)); my $sumxy = 0; $sumxy += ($x[$_] - $xmean)*($y[$_] - $ymean) for 0..$#x; return $sumxy; } sub slope { my($x, $y) = @_; sumxy($x, $y) / sumn(2, @{$x}); } __DATA__ TEXT1 By Federal Law, as a sysadmin, you're required to purchase Bug Insurance. The insurance policy will pay the plaintiff the damage incurred by each bug your system causes. Let $54.99 be the max possible damage claimable per bug, 5.49% the chances for each bug to independently occur. Using your "instinct" only, how much are you willing to pay for a policy that protect you against... TEXT2 PROMPT1 ... 11 bugs: ... 19 bugs: ... 24 bugs: ... 46 bugs: ... 84 bugs: ... 99 bugs: Press any key to quit. PROMPT2 RESULT1 You're a Gambler--code w/o your monitor on. You're a Risk-taker--code & pray, & never debug. You're a Stone-Cold Human Calculator--code in assembly. You're a Risk-Averser--even debug a plain text. You're a Wuss--even afraid of electrocution by your mouse. RESULT2

In reply to Are you a risk-taker? by chunlou

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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-04-23 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found