if (in_array($key, array('cats', 'trees'))) { if ($distinct > $ticketTap[$key]) { $goodSue++; } } else { if (in_array($key, array('pomeranians', 'goldfish'))) { if ($distinct < $ticketTap[$key]) { $goodSue++; } } else { if ($distinct === $ticketTap[$key]) { $goodSue++; } } } } if ($goodSue === 3) { return $sueId; } } return; } $sueList = getListOfSue(); $part1 = part1($ticketTap, $sueList); print 'Part1: ' . $part1; print PHP_EOL; $part2 = part2($ticketTap, $sueList); print 'Part2: ' . $part2; print PHP_EOL; //print_r($sueList); //print PHP_EOL;
} fclose($file); return $total; } function calculateSurfaceArea($dimensions) { return 2 * $dimensions[0] * $dimensions[1] + 2 * $dimensions[1] * $dimensions[2] + 2 * $dimensions[2] * $dimensions[0]; } function calculateAreaOfSmallestSide($dimensions) { return $dimensions[0] * $dimensions[1]; } function calculatePaperNeeded($dimensions) { return calculateAreaOfSmallestSide($dimensions) + calculateSurfaceArea($dimensions); } function calculateRibbonToWrap($dimensions) { return $dimensions[0] * 2 + $dimensions[1] * 2; } function calculateRibbonForBow($dimensions) { return $dimensions[0] * $dimensions[1] * $dimensions[2]; } function calculateRibbonNeeded($dimensions) { return calculateRibbonToWrap($dimensions) + calculateRibbonForBow($dimensions); } echo part1($fileName) + "\r\n"; echo "\n"; echo part2($fileName);
echo "Bad input"; break; } } } return $floor; } function part2($input) { $count = 1; $inputArray = str_split($input); foreach ($inputArray as $character) { if ($character == UPFLOOR) { $floor++; } else { if ($character == DOWNFLOOR) { $floor--; } else { echo "Bad input"; break; } } if ($floor == -1) { return $count; } else { $count++; } } } echo part1($input); echo part2($input);
* Compute part 2 * * @param integer $input Goal */ function part2($input) { $current = 780000; // As i know the answer, let's avoid wasting time and don't start with 1 while (1) { $dividerList = getDividers($current); foreach ($dividerList as $divider) { if ($divider * 50 < $current) { unset($dividerList[$divider]); } } $sum = 0; $i = 0; foreach ($dividerList as $divider) { $sum += $divider * 11; } if ($sum >= $input) { break; } $current++; } print 'Part2: ' . $current; print PHP_EOL; } $input = 33100000; part1($input); part2($input);