This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
//$input = file('sample.txt', FILE_IGNORE_NEW_LINES); | |
$input = file('input.txt', FILE_IGNORE_NEW_LINES); | |
$totalNextNumbers = 0; | |
$totalPreviousNumbers = 0; | |
foreach ($input as $line) { | |
$numbers = explode(' ', $line); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
//$input = file('sample.txt', FILE_IGNORE_NEW_LINES); | |
//$input = file('sample-part2.txt', FILE_IGNORE_NEW_LINES); | |
$input = file('input.txt', FILE_IGNORE_NEW_LINES); | |
$instructions = $input[0]; | |
printf('Instructions for %d lines: %s' . PHP_EOL, count($input) - 2, $instructions); | |
$nodes = parseNodes(array_slice($input, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
$input = file('input.txt'); | |
//$input = file('sample.txt'); | |
$times = array_filter(explode(' ', trim(substr($input[0], strpos($input[0], ':') + 1)))); | |
$distances = array_filter(explode(' ', trim(substr($input[1], strpos($input[1], ':') + 1)))); | |
$races = array_combine($times, $distances); | |
$part1Answer = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$input = file('input.txt', FILE_IGNORE_NEW_LINES); | |
//$input = file('sample.txt', FILE_IGNORE_NEW_LINES); | |
$seeds = explode(' ', str_replace('seeds: ', '', $input[0])); | |
$seedToSoilMap = getMapByHeader($input, 'seed-to-soil map:'); | |
$soilToFertilizerMap = getMapByHeader($input, 'soil-to-fertilizer map:'); | |
$fertilizerToToWaterMap = getMapByHeader($input, 'fertilizer-to-water map:'); | |
$waterToLightMap = getMapByHeader($input, 'water-to-light map:'); | |
$lightToTemperatureMap = getMapByHeader($input, 'light-to-temperature map:'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
$input = file('input.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | |
$sumOfNumbers = 0; | |
foreach ($input as $line) { | |
printf('turned %s into ', $line); | |
$line = replaceNumberWordsWithDigits($line); | |
printf('%s' . PHP_EOL, $line); | |
$digits = getFirstAndLastDigitsFromLine($line); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
$input = file('input.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); | |
$maxRed = 12; | |
$maxGreen = 13; | |
$maxBlue = 14; | |
$validCount = 0; |