codingtests/ProjectEuler/031/problem31.php

34 lines
1.1 KiB
PHP
Raw Normal View History

2024-06-26 13:16:36 +00:00
<?php
define("TOTAL", 200);
$combo=0;
$sum = 200;
for ($a = 0; $a <= (TOTAL / 200); $a++) {
$sum_a = TOTAL - ($a * 200);
for ($b = 0; $b <= ($sum_a / 100); $b++) {
$sum_b = $sum_a - ($b * 100);
for ($c = 0; $c <= ($sum_b / 50); $c++) {
$sum_c = $sum_b - ($c * 50);
for ($d = 0; $d <= ($sum_c / 20); $d++) {
$sum_d = $sum_c - ($d * 20);
for ($e = 0; $e <= ($sum_d / 10); $e++) {
$sum_e = $sum_d - ($e * 10);
for ($f = 0; $f <= ($sum_e / 5); $f++) {
$sum_f = $sum_e - ($f * 5);
for ($g = 0; $g <= ($sum_e / 2); $g++) {
$sum_g = $sum_f - ($g * 2);
for ($h = 0; $h <= ($sum_g / 1); $h++) {
if ($a * 200 + $b * 100 + $c * 50 + $d * 20 + $e * 10 + $f * 5 + $g * 2 + $h == TOTAL) {
$combo++;
}
}
}
}
}
}
}
}
}
echo $combo;