Making things more versatile for day 2.
This commit is contained in:
parent
f39448a54e
commit
7f79c6079a
@ -64,35 +64,23 @@ class Box {
|
||||
|
||||
}
|
||||
|
||||
function day2part1() {
|
||||
function day2(int $part = 1) {
|
||||
$box_dimension_list = file_get_contents('./2015/inputs/day2.txt');
|
||||
$box_dimension_list = explode(PHP_EOL, $box_dimension_list);
|
||||
$wrapping_paper_total = 0;
|
||||
$total = 0;
|
||||
foreach ($box_dimension_list as $box_dimensions) {
|
||||
if (strlen($box_dimensions) < 1) {
|
||||
continue;
|
||||
}
|
||||
$box = new Box();
|
||||
$box->extractDimensions($box_dimensions);
|
||||
$wrapping_paper_total = $wrapping_paper_total + $box->calculateRequiredFootage();
|
||||
if ($part == 1) {
|
||||
$total = $total + $box->calculateRequiredFootage();
|
||||
}
|
||||
return $wrapping_paper_total;
|
||||
elseif ($part == 2) {
|
||||
$total = $total + $box->calculateRibbonRequirements();
|
||||
}
|
||||
}
|
||||
return $total;
|
||||
}
|
||||
|
||||
function day2part1b() {
|
||||
$box_dimension_list = file_get_contents('./2015/inputs/day2.txt');
|
||||
$box_dimension_list = explode(PHP_EOL, $box_dimension_list);
|
||||
$ribbon_requirements = 0;
|
||||
foreach ($box_dimension_list as $box_dimensions) {
|
||||
if (strlen($box_dimensions) < 1) {
|
||||
continue;
|
||||
}
|
||||
$box = new Box();
|
||||
$box->extractDimensions($box_dimensions);
|
||||
$ribbon_requirements = $ribbon_requirements + $box->calculateRibbonRequirements();
|
||||
}
|
||||
|
||||
return $ribbon_requirements;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -8,8 +8,8 @@ foreach ($days as $day) {
|
||||
$solutions = [];
|
||||
$solutions['day_1']['part_1'] = day1solution1();
|
||||
$solutions['day_1']['part_2'] = day1solution1b();
|
||||
$solutions['day_2']['part_1'] = day2part1();
|
||||
$solutions['day_2']['part_2'] = day2part1b();
|
||||
$solutions['day_2']['part_1'] = day2(1);
|
||||
$solutions['day_2']['part_2'] = day2(2);
|
||||
|
||||
// OUTPUT THE SOLUTIONS WE HAVE.
|
||||
foreach ($solutions as $day => $parts) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user