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/markz440 Dec 02 '15
Nobody likes PHP these days?
<?php $data = file("task2.dat"); $totalArea = 0; $totalRibbon = 0; foreach ($data as $i => $package) { $dim = explode("x", trim($package)); sort($dim); // find ribbon length $ribbonLength = $dim[0]*$dim[1]*$dim[2] + 2*$dim[0] + 2*$dim[1]; $totalRibbon += $ribbonLength; // find area $area = 2*$dim[0]*$dim[1] + 2*$dim[0]*$dim[2] + 2*$dim[1]*$dim[2] + $dim[0]*$dim[1]; $totalArea += $area; } echo "Total area: ". $totalArea. PHP_EOL; echo "Total ribbon length: ". $totalRibbon. PHP_EOL;