Exemplo n.º 1
0
 public function __invoke()
 {
     $grid = new LightingGridWithAdjustableBrightness();
     $parser = new InstructionsParser($grid);
     $input = file_get_contents(__DIR__ . "/../../input/Day6/Puzzle1");
     $parser->parse($input);
     echo "Cumulative brightness of lights: " . $grid->getCumulativeBrightness();
 }
Exemplo n.º 2
0
 public function __invoke()
 {
     $grid = new LightingGrid();
     $parser = new InstructionsParser($grid);
     $input = file_get_contents(__DIR__ . "/../../input/Day6/Puzzle1");
     $parser->parse($input);
     echo "Number of turned on lights: " . $grid->getNumberOfTurnOnLights();
 }
Exemplo n.º 3
0
 public function __invoke()
 {
     $parser = new InstructionsParser();
     $parsed = $parser->parse($this->loadInput("Day19/Puzzle1"));
     $runner = new ReplacementRunner($parsed['replacements']);
     $possibles = $runner->possibleReplacements($parsed['molecule']);
     $this->write("Number of possibles: " . count($possibles));
 }
Exemplo n.º 4
0
 public function __invoke()
 {
     $elevator = new Elevator();
     $parser = new InstructionsParser($elevator);
     $input = file_get_contents(__DIR__ . "/../../input/Day1/Puzzle1");
     $parser->parseInstructions($input);
     echo "Final floor: " . $elevator->getFloor();
 }
Exemplo n.º 5
0
 public function __invoke()
 {
     $santa = new Santa();
     $parser = new InstructionsParser($santa);
     $input = file_get_contents(__DIR__ . "/../../input/Day3/Puzzle3");
     $parser->parse($input);
     echo "Total number of unique houses visited: " . $santa->getNumberOfUniqueHousesDeliveredTo();
 }
Exemplo n.º 6
0
 public function __invoke()
 {
     $parser = new InstructionsParser();
     $parsed = $parser->parse($this->loadInput("Day19/Puzzle1"));
     $runner = new ReplacementRunner($parsed['replacements']);
     $steps = $runner->minimumNumberStepsForBuildingMolecule($parsed['molecule']);
     $this->write("Steps: " . $steps);
 }
Exemplo n.º 7
0
 public function __invoke()
 {
     $input = $this->loadInput("Day15/Puzzle1");
     $parser = new InstructionsParser();
     $larder = $parser->parse($input);
     $combinations = new Combinations();
     $planner = new RecipePlanner($larder, $combinations);
     $megaCookie = $planner->megaCookie(100);
     $this->write("Mega cookie value: " . $megaCookie->totalScoreForRecipe());
 }
Exemplo n.º 8
0
 public function __invoke()
 {
     $input = $this->loadInput("Day14/Puzzle1");
     $parser = new InstructionsParser();
     $herd = $parser->parse($input);
     $race = new Race($herd);
     $duration = 2503;
     $winner = $race->pointsWinnerAfter($duration);
     $this->write("Winner: " . $winner->name() . " with " . $winner->points() . " points");
 }
Exemplo n.º 9
0
 public function __invoke()
 {
     $elevator = new Elevator();
     $parser = new InstructionsParser($elevator);
     $input = file_get_contents(__DIR__ . "/../../input/Day1/Puzzle1");
     $parser->parseInstructions($input);
     $log = $parser->getInstructionsLog();
     $logEntryKey = array_search("-1", $log);
     echo "Instruction # entered for first entry to basement: " . ($logEntryKey + 1);
 }
Exemplo n.º 10
0
 public function __invoke()
 {
     $input = $this->loadInput("Day14/Puzzle1");
     $parser = new InstructionsParser();
     $herd = $parser->parse($input);
     $race = new Race($herd);
     $duration = 2503;
     $winner = $race->winnerAfter($duration);
     $this->write("Winner: " . $winner->name() . ", who has flown " . $winner->distanceAfter($duration));
 }
Exemplo n.º 11
0
 public function __invoke()
 {
     $circuit = new Circuit(new WiresCollection());
     $parser = new InstructionsParser($circuit);
     $input = file_get_contents(__DIR__ . "/../../input/Day7/Puzzle1");
     $instructions = explode(PHP_EOL, $input);
     while (true) {
         foreach ($instructions as $k => $instruction) {
             if ($parser->parse($instruction) !== false) {
                 unset($instructions[$k]);
             }
         }
         if (empty($instructions)) {
             break;
         }
     }
     echo "Signal provided to wire 'a':" . $circuit->getWireValue("a");
 }
Exemplo n.º 12
0
 public function __invoke()
 {
     $input = $this->loadInput("Day16/Puzzle1");
     $parser = new InstructionsParser();
     $gifterProperties = ["children" => 3, "cats" => 7, "samoyeds" => 2, "pomeranians" => 3, "akitas" => 0, "vizslas" => 0, "goldfish" => 5, "trees" => 3, "cars" => 2, "perfumes" => 1];
     foreach (explode(PHP_EOL, $input) as $instruction) {
         $sue = $parser->parse($instruction);
         $couldBeThisSue = true;
         foreach ($gifterProperties as $property => $value) {
             if (!$sue->couldBe($property, $value)) {
                 $couldBeThisSue = false;
                 break;
             }
         }
         if ($couldBeThisSue) {
             break;
         }
     }
     $this->write("Sue number: " . $sue->number());
 }