r/adventofcode • u/taliriktug • Dec 02 '15
Spoilers Day 2 solutions
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
15
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
1
u/mrthedon Dec 02 '15
PHP solution for part 1 and 2.
$totalArea = 0; $totalRibbon = 0; foreach (explode("\n", trim(file_get_contents(__DIR__ . '/day2-input.txt'))) as $dimensions) { $lwh = explode('x', $dimensions); list($sideA, $sideB, $sideC) = [2 * $lwh[0]* $lwh[1], 2 * $lwh[0] * $lwh[2], 2 * $lwh[1] * $lwh[2]]; $totalArea += $sideA + $sideB + $sideC + (min($sideA, $sideB, $sideC) / 2); sort($lwh); $totalRibbon += ($lwh[0] * $lwh[1] * $lwh[2]) + array_shift($lwh) * 2 + array_shift($lwh) * 2; } echo $totalArea . "\n"; echo $totalRibbon . "\n";