Day 1 solution and individual routes to show code.
This commit is contained in:
parent
91d5eb7f0a
commit
2b2bc8f134
BIN
2025/.DS_Store
vendored
Normal file
BIN
2025/.DS_Store
vendored
Normal file
Binary file not shown.
@ -3,14 +3,54 @@
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use Aoc2025\Days\Day1;
|
||||
use Aoc2025\Days\Day2;
|
||||
use Aoc2025\Services\Template;
|
||||
|
||||
|
||||
// First check if this is solution page request.
|
||||
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
||||
if (str_starts_with($path, '/solutions')) {
|
||||
$path_exploded = explode('/', $path);
|
||||
if (count($path_exploded) < 3) {
|
||||
header('Location: /');
|
||||
}
|
||||
$day = str_replace("-", '', $path_exploded[2]);
|
||||
$day = ucfirst($day);
|
||||
try {
|
||||
$code = @file_get_contents(__DIR__ . '/src/Days/' . $day . '.php');
|
||||
if (!$code) {
|
||||
throw new Exception('File not found');
|
||||
}
|
||||
else {
|
||||
echo "<pre><code class='language-php'>" . htmlspecialchars($code) . "</code></pre>";
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
header('Location: /');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if ($path != '/') {
|
||||
header('Location: /');
|
||||
}
|
||||
|
||||
// Day 1.
|
||||
$day_1 = new Day1();
|
||||
$day_1_answer = $day_1->run();
|
||||
|
||||
// Day 2.
|
||||
$day_2 = new Day2();
|
||||
$day_2_answer = $day_2->run();
|
||||
|
||||
|
||||
// Render the template.
|
||||
$template = new Template('main.html');
|
||||
$substitutions = [
|
||||
'day_1_answer' => $day_1_answer,
|
||||
'day_1_answer' => $day_1_answer['part_1'],
|
||||
'day_1_answer_2' => $day_1_answer['part_2'],
|
||||
'day_2_answer' => $day_2_answer['part_1'],
|
||||
'day_2_answer_2' => $day_2_answer['part_2'],
|
||||
];
|
||||
$response = $template->render($substitutions);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
0
2025/inputs/day_2_input.txt
Normal file
0
2025/inputs/day_2_input.txt
Normal file
@ -3,16 +3,66 @@
|
||||
namespace Aoc2025\Days;
|
||||
|
||||
use Aoc2025\Day;
|
||||
use Aoc2025\Services\Dial;
|
||||
|
||||
class Day1 extends Day {
|
||||
|
||||
/**
|
||||
* Count of zeroes ended on.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $zeroCount = 0;
|
||||
|
||||
/**
|
||||
* Count of zeroes encountered and ended on.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $zeroCount2 = 0;
|
||||
|
||||
/**
|
||||
* Run the day's challenge.
|
||||
*/
|
||||
public function run() {
|
||||
$input = $this->getInputFile('day_1_input.txt');
|
||||
return "12345";
|
||||
$input = explode("\n", $input);
|
||||
$instructions = array_filter($input);
|
||||
|
||||
$dial = new Dial();
|
||||
$dial->setPosition(50);
|
||||
|
||||
foreach ($instructions as $instruction) {
|
||||
$distance = substr($instruction, 1);
|
||||
$direction = substr($instruction, 0, 1);
|
||||
if ($direction == 'L') {
|
||||
for ($i = 0; $i < $distance; $i++) {
|
||||
$dial->moveLeft();
|
||||
if ($dial->getPosition() == 0 && $i < $distance - 1) {
|
||||
$this->zeroCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($direction == 'R') {
|
||||
for ($i = 0; $i < $distance; $i++) {
|
||||
$dial->moveRight();
|
||||
if ($dial->getPosition() == 0 && $i < $distance - 1) {
|
||||
$this->zeroCount2++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($dial->getPosition() == 0) {
|
||||
$this->zeroCount++;
|
||||
$this->zeroCount2++;
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'part_1' => $this->zeroCount,
|
||||
'part_2' => $this->zeroCount2,
|
||||
];
|
||||
|
||||
return $dial->getHitZero();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
17
2025/src/Days/Day2.php
Normal file
17
2025/src/Days/Day2.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Aoc2025\Days;
|
||||
|
||||
use Aoc2025\Day;
|
||||
|
||||
class Day2 extends Day {
|
||||
|
||||
public function run() {
|
||||
$input = $this->getInputFile('day_2_input.txt');
|
||||
|
||||
return [
|
||||
'part_1' => 0,
|
||||
'part_2' => 0,
|
||||
];
|
||||
}
|
||||
}
|
||||
60
2025/src/Services/Dial.php
Normal file
60
2025/src/Services/Dial.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Aoc2025\Services;
|
||||
|
||||
class Dial {
|
||||
|
||||
/**
|
||||
* The maximum number the dial can be set to.
|
||||
*/
|
||||
const MAX_NUMBER = 99;
|
||||
|
||||
/**
|
||||
* The minimum number the dial can be set to.
|
||||
*/
|
||||
const MIN_NUMBER = 0;
|
||||
|
||||
/**
|
||||
* The position of the dial.
|
||||
*/
|
||||
protected $position;
|
||||
|
||||
/**
|
||||
* Moves the dial left.
|
||||
*/
|
||||
public function moveLeft() {
|
||||
if ($this->position == self::MIN_NUMBER) {
|
||||
$this->position = self::MAX_NUMBER;
|
||||
}
|
||||
else {
|
||||
$this->position = $this->position - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the dial right.
|
||||
*/
|
||||
public function moveRight() {
|
||||
if ($this->position == self::MAX_NUMBER) {
|
||||
$this->position = self::MIN_NUMBER;
|
||||
}
|
||||
else {
|
||||
$this->position = $this->position + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position of the dial.
|
||||
*/
|
||||
public function setPosition($position) {
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the position of the dial.
|
||||
*/
|
||||
public function getPosition() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
}
|
||||
@ -13,8 +13,8 @@
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="bold">Part 1: {{ day_1_answer }}</p>
|
||||
<p class="bold">Part 2:</p>
|
||||
<button>View Code</button>
|
||||
<p class="bold">Part 2: {{ day_1_answer_2 }}</p>
|
||||
<a class="btn" href="/solutions/day-1">View Code</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -23,9 +23,9 @@
|
||||
<h2 class="bitcount fs-1">Day 2</h2>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<p class="bold">Part 1:</p>
|
||||
<p class="bold">Part 2:</p>
|
||||
<button>View Code</button>
|
||||
<p class="bold">Part 1: {{ day_2_answer }}</p>
|
||||
<p class="bold">Part 2: {{ day_2_answer_2 }}</p>
|
||||
<a class="btn" href="/solutions/day-2">View Code</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@ -110,7 +110,12 @@ ul {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
a.btn {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button, .btn {
|
||||
background-color: var(--primary-0);
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
@ -125,10 +130,10 @@ button {
|
||||
text-decoration: none;
|
||||
transition: background-color 0.2s ease-in-out;
|
||||
}
|
||||
button:hover {
|
||||
button:hover, .btn:hover {
|
||||
background-color: var(--primary-1);
|
||||
}
|
||||
button:active {
|
||||
button:active, .btn:active {
|
||||
background-color: var(--primary-2);
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
{"version":3,"sourceRoot":"","sources":["style.scss","partials/font-scale.scss","partials/cards.scss"],"names":[],"mappings":"AACQ;AAGR;EAEE;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA,yBACE;;;AAYJ;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EAXF;IAYI;IACA;;;;AAIJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;AAAA;AAAA;AAAA;AAAA;EAKE;EACA;EACA;;AAEA;EATF;AAAA;AAAA;AAAA;AAAA;IAUI;;;;AAIJ;EACE;;;AAGF;EACE;EACA;;AAEA;EACE;;;AAIJ;EACE;EACA;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAGF;EACE;;;AAIJ;EACE;EACA;EACA;;;ACpJF;EACE;EACA;;AAEA;EAJF;IAKI;IACA;;;AAGF;EATF;IAUI;IACA;;;;ACXJ;EACE;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;;AAEA;EACE","file":"style.css"}
|
||||
{"version":3,"sourceRoot":"","sources":["style.scss","partials/font-scale.scss","partials/cards.scss"],"names":[],"mappings":"AACQ;AAGR;EAEE;EACA;EACA;EACA;EACA;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA,yBACE;;;AAYJ;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EAXF;IAYI;IACA;;;;AAIJ;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;AAAA;AAAA;AAAA;AAAA;EAKE;EACA;EACA;;AAEA;EATF;AAAA;AAAA;AAAA;AAAA;IAUI;;;;AAIJ;EACE;;;AAGF;EACE;EACA;;AAEA;EACE;;;AAIJ;EACE;EACA;EACA;;;AAGF;EACE;EACA;;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;;AAGF;EACE;;;AAIJ;EACE;EACA;EACA;;;ACzJF;EACE;EACA;;AAEA;EAJF;IAKI;IACA;;;AAGF;EATF;IAUI;IACA;;;;ACXJ;EACE;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;;AAEA;EACE","file":"style.css"}
|
||||
@ -119,7 +119,12 @@ ul {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
button {
|
||||
a.btn {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
button, .btn {
|
||||
background-color: var(--primary-0);
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user