Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Are you a risk-taker?

by chunlou (Curate)
on Aug 06, 2003 at 03:58 UTC ( #281265=CUFP: 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

Comment on Are you a risk-taker?
Download Code
Re: Are you a risk-taker?
by rje (Deacon) on Aug 13, 2003 at 18:28 UTC
    I'm proud to announce that my result is

    You're a Stone-Cold Human Calculator--code in assembly. You're paying 98% of the "right" price.
    ...that is, if you count my guesstimation as using my "instinct".

    rje

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://281265]
Approved by graff
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2015-07-04 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls