Created
November 4, 2023 15:56
-
-
Save artlung/2c011f32bacbfd5333c9a6b89fc7db0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$year = 2024; | |
$adult_days_and_prices = [ | |
'wed' => 59, | |
'thu' => 79, | |
'fri' => 79, | |
'sat' => 79, | |
'sun' => 54, | |
]; | |
$senior_days_and_prices = [ | |
'wed' => 30, | |
'thu' => 40, | |
'fri' => 40, | |
'sat' => 40, | |
'sun' => 27, | |
]; | |
$handling_fee_per_member = 15; | |
$days_and_possible_values = [ | |
'wed' => [true, false], | |
'thu' => [true, false], | |
'fri' => [true, false], | |
'sat' => [true, false], | |
'sun' => [true, false], | |
]; | |
// iterate all possible combinations of days | |
// and display the fee for each | |
$days = array_keys($adult_days_and_prices); | |
$options = [ | |
'regular' => 'Regular Adult Prices', | |
'senior' => 'Junior/Military/Senior Prices', | |
]; | |
foreach ($options as $option => $title) { | |
print "=====================================\n\n"; | |
print " $year Comic-Con Registration Fees\n"; | |
print " $title\n\n"; | |
if ($option === 'regular') { | |
$days_and_prices = $adult_days_and_prices; | |
} else { | |
$days_and_prices = $senior_days_and_prices; | |
} | |
print "Wed Thu Fri Sat Sun Total +Fee\n"; | |
print "-------------------------------------\n"; | |
$wed = $days_and_possible_values['wed']; | |
$thu = $days_and_possible_values['thu']; | |
$fri = $days_and_possible_values['fri']; | |
$sat = $days_and_possible_values['sat']; | |
$sun = $days_and_possible_values['sun']; | |
$lines = []; | |
foreach ($wed as $wed_value) { | |
foreach ($thu as $thu_value) { | |
foreach ($fri as $fri_value) { | |
foreach ($sat as $sat_value) { | |
foreach ($sun as $sun_value) { | |
// if none of the days are true, continue, no preview night without another day | |
if (!$thu_value && !$fri_value && !$sat_value && !$sun_value) { | |
continue; | |
} | |
$days = [ | |
'wed' => $wed_value, | |
'thu' => $thu_value, | |
'fri' => $fri_value, | |
'sat' => $sat_value, | |
'sun' => $sun_value, | |
]; | |
$total = 0; | |
$plus_fee = 0; | |
foreach ($days as $day => $value) { | |
if ($value) { | |
$total += $days_and_prices[$day]; | |
} | |
} | |
$plus_fee = $total + $handling_fee_per_member; | |
$lines[] = [ | |
'total' => $plus_fee, | |
'line' => sprintf("%-5s%-5s%-5s%-5s%-5s%6s%6s\n", | |
($wed_value ? 'Wed' : ' '), | |
($thu_value ? 'Thu' : ' '), | |
($fri_value ? 'Fri' : ' '), | |
($sat_value ? 'Sat' : ' '), | |
($sun_value ? 'Sun' : ' '), | |
'$' . $total, | |
'$' . $plus_fee) | |
]; | |
} | |
} | |
} | |
} | |
} | |
// sort $lines by $line['total'] | |
usort($lines, function($a, $b) { | |
return $b['total'] <=> $a['total']; | |
}); | |
foreach ($lines as $line) { | |
print $line['line']; | |
} | |
} | |
print "=====================================\n"; | |
print "\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment