Compare commits

..

No commits in common. 'c1ff5f7242c0fd8b4baac50bb8926041e5c52da0' and 'c29d6d937b4cb52ddafab6518c590fde67b3c4a0' have entirely different histories.

  1. 91
      public/days/Day2.php
  2. 15
      public/index.php
  3. 11
      public/main.js
  4. 2
      public/run.php
  5. 5
      public/styles.css

@ -1,91 +0,0 @@
<?php
final class Day2 extends Day {
function part1(): string {
$safeCount = 0;
foreach ($this->input as $line){
$levels = array_map('intval', explode(' ', $line));
$isSafe = true;
$direction = null;
for ($i = 0; $i < count($levels) - 1; $i++){
$levelNow = $levels[$i];
$levelThen = $levels[$i + 1];
$change = abs($levelThen - $levelNow);
if ($change < 1 || $change > 3){
$isSafe = false;
break;
}
if ($direction === null){
$direction = $levelThen > $levelNow;
}
if ($direction !== ($levelThen > $levelNow)){
$isSafe = false;
break;
}
}
if ($isSafe)
$safeCount++;
}
return strval($safeCount);
}
function part2(): string {
$safeCount = 0;
foreach ($this->input as $line){
$levels = array_map('intval', explode(' ', $line));
$isSafe = false;
for ($removeLevelIndex = -1; $removeLevelIndex < count($levels); $removeLevelIndex++){
$localLevels = $levels;
if ($removeLevelIndex > -1){
array_splice($localLevels, $removeLevelIndex, 1);
}
$levelSetIsSafe = true;
$direction = null;
for ($i = 0; $i < count($localLevels) - 1; $i++){
$levelNow = $localLevels[$i];
$levelThen = $localLevels[$i + 1];
$change = abs($levelThen - $levelNow);
if ($change < 1 || $change > 3){
$levelSetIsSafe = false;
break;
}
if ($direction === null){
$direction = $levelThen > $levelNow;
}
if ($direction !== ($levelThen > $levelNow)){
$levelSetIsSafe = false;
break;
}
}
if ($levelSetIsSafe){
$isSafe = true;
break;
}
}
if ($isSafe)
$safeCount++;
}
return strval($safeCount);
}
}

@ -5,22 +5,9 @@
</head>
<body>
<div id="response">Response</div>
<?php
for ($i = 1; $i <= 25; $i++){
echo
"<div class='day' id='day-$i'>
<h3>Day $i</h3>
<button data-url='/run.php?day=$i&part=1'>Part 1</button>
<button data-url='/run.php?day=$i&part=2'>Part 2</button>
</div>";
}
?>
<script type="application/javascript" src="main.js"></script>
?>
</body>
</html>

@ -1,11 +0,0 @@
for (let i = 1; i <= 25; i++){
let buttons = document.querySelectorAll(`#day-${i} > button`);
buttons.forEach(button => {
button.addEventListener('click', async () => {
const response = await (await fetch(button.dataset['url'])).json();
document.getElementById('response').innerText = response.result;
});
});
}

@ -30,9 +30,9 @@ if ($dayNumber){
'data' => null
];
echo json_encode($response);
die();
}
}
}
echo json_encode([]);

@ -4,10 +4,7 @@ body {
background-color: rgb(30, 30, 30);
}
body > * {
color: white;
}
* {
color: white;
font-family: "Red Hat Mono", serif;
}
Loading…
Cancel
Save