#!/usr/bin/perl
use CGI;
$q = new CGI;
print $q->header;
print $q->start_html(-title=>'Deal or No Deal',-BGCOLOR=>'white'),
$q->h1('--Deal or No Deal--'),
$q->startform();
@left = qw/ 0.01 1 5 10 20 50
75 100 200 300 400 500 750/;
@right= qw/1,000 5,000 10,000 25,000 50,000 75,000
100,000 200,000 300,000 400,000 500,000 750,000 1,000,000/;
my $i = 0;
print "<table>\n";
for (@left)
{
print $q->Tr($q->th([
$q->checkbox(-name=>"cl$i",
-checked=>'checked',
-value=>'YES',
-label=>'').
$q->textfield(-name=>"l$i",
-default=>$left[$i],
-size=>9,
-override=>0),
$q->textfield(-name=>"r$i",
-default=>$right[$i],
-size=>9,
-override=>0).
$q->checkbox(-name=>"cr$i",
-checked=>'checked',
-value=>'YES',
-label=>'')
])), "\n";
$i++;
}
print "</table>";
print $q->submit(-name=>'Calculate'),
$q->endform()
;
if (@all = $q->param())
{
my $acc = 0;
my $count = 0;
for (@all)
{
if(/c((?:l|r)\d+)/)
{
my $val = $q->param($1);
$val =~ s/[^.0-9]//g;
$count++;
$sum += $val;
}
}
print "<p>Expected Value: ".'$';
printf "%.2f<hr>", $sum/$count;
}
print $q->end_html;
Too simple perhaps? (Score:1)
Fortunately, computers are fast.
You might want to take the simple approach of just running every possible game recursively, and then averaging all the results from there.
Re:Too simple perhaps? (Score:1)