Update stuff
This commit is contained in:
parent
d3f2406b23
commit
6915c35fed
@ -1,6 +1,6 @@
|
|||||||
# https://taskfile.dev
|
# https://taskfile.dev
|
||||||
|
|
||||||
version: '3'
|
version: "3"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
default:
|
default:
|
||||||
@ -11,21 +11,21 @@ tasks:
|
|||||||
check:
|
check:
|
||||||
cmds:
|
cmds:
|
||||||
- task: echo_title
|
- task: echo_title
|
||||||
vars: {TITLE: Running php-cs-fixer...}
|
vars: { TITLE: Running php-cs-fixer... }
|
||||||
- task: style
|
- task: style
|
||||||
- task: echo_title
|
- task: echo_title
|
||||||
vars: {TITLE: Running phpstan...}
|
vars: { TITLE: Running phpstan... }
|
||||||
- task: phpstan
|
- task: phpstan
|
||||||
- task: echo_title
|
- task: echo_title
|
||||||
vars: { TITLE: Running rector... }
|
vars: { TITLE: Running rector... }
|
||||||
- task: rector
|
- task: rector
|
||||||
- task: echo_title
|
- task: echo_title
|
||||||
vars: {TITLE: Running phpunit}
|
vars: { TITLE: Running pest }
|
||||||
- task: phpunit
|
- task: pest
|
||||||
|
|
||||||
style:
|
style:
|
||||||
cmds:
|
cmds:
|
||||||
- php vendor/bin/php-cs-fixer fix
|
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer fix
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
phpstan:
|
phpstan:
|
||||||
@ -38,7 +38,7 @@ tasks:
|
|||||||
- php vendor/bin/rector process
|
- php vendor/bin/rector process
|
||||||
silent: true
|
silent: true
|
||||||
|
|
||||||
phpunit:
|
pest:
|
||||||
cmds:
|
cmds:
|
||||||
- php vendor/bin/pest
|
- php vendor/bin/pest
|
||||||
silent: true
|
silent: true
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"php": "^8.3",
|
"php": "^8.3",
|
||||||
"ext-mbstring": "*",
|
"ext-mbstring": "*",
|
||||||
"cebe/markdown": "^1.2",
|
"cebe/markdown": "^1.2",
|
||||||
"laravel/prompts": "^0.1.13",
|
"laravel/prompts": "^0.3",
|
||||||
"nette/php-generator": "^4.1",
|
"nette/php-generator": "^4.1",
|
||||||
"phppkg/cli-markdown": "^2.0",
|
"phppkg/cli-markdown": "^2.0",
|
||||||
"symfony/console": "^7"
|
"symfony/console": "^7"
|
||||||
@ -22,12 +22,13 @@
|
|||||||
"friendsofphp/php-cs-fixer": "^3.3",
|
"friendsofphp/php-cs-fixer": "^3.3",
|
||||||
"jetbrains/phpstorm-attributes": "^1.0",
|
"jetbrains/phpstorm-attributes": "^1.0",
|
||||||
"nunomaduro/collision": "^8",
|
"nunomaduro/collision": "^8",
|
||||||
"pestphp/pest": "^2.26",
|
"pestphp/pest": "^3.5",
|
||||||
"phpstan/phpstan": "^1.2",
|
"phpstan/phpstan": "^2.0",
|
||||||
"rector/rector": "^1.0",
|
"rector/rector": "^2.0",
|
||||||
"robiningelbrecht/phpunit-pretty-print": "^1.2",
|
"robiningelbrecht/phpunit-pretty-print": "^1.2",
|
||||||
"symfony/var-dumper": "^7"
|
"symfony/var-dumper": "^7"
|
||||||
},
|
},
|
||||||
|
"minimum-stability": "dev",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"trizz\\AdventOfCode\\": "src/"
|
"trizz\\AdventOfCode\\": "src/"
|
||||||
|
1405
composer.lock
generated
1405
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -21,11 +21,9 @@ final class Day2 extends Solution
|
|||||||
$horizontal = 0;
|
$horizontal = 0;
|
||||||
|
|
||||||
foreach ($data as $current) {
|
foreach ($data as $current) {
|
||||||
/**
|
|
||||||
* @var string $direction
|
|
||||||
* @var int $distance
|
|
||||||
*/
|
|
||||||
[$direction, $distance] = explode(' ', $current);
|
[$direction, $distance] = explode(' ', $current);
|
||||||
|
$direction = (string) $direction;
|
||||||
|
$distance = (int) $distance;
|
||||||
|
|
||||||
match ($direction) {
|
match ($direction) {
|
||||||
'forward' => $horizontal += $distance,
|
'forward' => $horizontal += $distance,
|
||||||
@ -46,11 +44,9 @@ final class Day2 extends Solution
|
|||||||
$horizontal = 0;
|
$horizontal = 0;
|
||||||
|
|
||||||
foreach ($data as $current) {
|
foreach ($data as $current) {
|
||||||
/**
|
|
||||||
* @var string $direction
|
|
||||||
* @var int $distance
|
|
||||||
*/
|
|
||||||
[$direction, $distance] = explode(' ', $current);
|
[$direction, $distance] = explode(' ', $current);
|
||||||
|
$direction = (string) $direction;
|
||||||
|
$distance = (int) $distance;
|
||||||
|
|
||||||
// Can't use 'match' here because of the multiple expressions for 'forward'.
|
// Can't use 'match' here because of the multiple expressions for 'forward'.
|
||||||
switch ($direction) {
|
switch ($direction) {
|
||||||
|
@ -52,6 +52,10 @@ final class Day7 extends Solution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($fuelPerPosition)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return (int) min($fuelPerPosition);
|
return (int) min($fuelPerPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ final class Day8 extends Solution
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[\Override]
|
#[\Override]
|
||||||
public function part2(array $data): int|string
|
public function part2(array $data): int
|
||||||
{
|
{
|
||||||
$sequences = [];
|
$sequences = [];
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ final class Day2 extends Solution
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, array<int, string>>
|
* @return array{string, non-empty-list<string>}
|
||||||
*/
|
*/
|
||||||
private function getHand(string $line): array
|
private function getHand(string $line): array
|
||||||
{
|
{
|
||||||
|
@ -30,6 +30,17 @@ final class Day3 extends Solution
|
|||||||
$numbers = $this->checkLocation($row, $col);
|
$numbers = $this->checkLocation($row, $col);
|
||||||
$top = (int) $this->processNumbers($numbers['top'], sum: true);
|
$top = (int) $this->processNumbers($numbers['top'], sum: true);
|
||||||
$bottom = (int) $this->processNumbers($numbers['bottom'], sum: true);
|
$bottom = (int) $this->processNumbers($numbers['bottom'], sum: true);
|
||||||
|
if ($numbers === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($numbers['left'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($numbers['right'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$score += $top + $bottom + max($numbers['left']) + max($numbers['right']);
|
$score += $top + $bottom + max($numbers['left']) + max($numbers['right']);
|
||||||
}
|
}
|
||||||
@ -54,6 +65,18 @@ final class Day3 extends Solution
|
|||||||
|
|
||||||
$top = (array) $this->processNumbers($numbers['top']);
|
$top = (array) $this->processNumbers($numbers['top']);
|
||||||
$bottom = (array) $this->processNumbers($numbers['bottom']);
|
$bottom = (array) $this->processNumbers($numbers['bottom']);
|
||||||
|
if ($numbers === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($numbers['left'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($numbers['right'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$left = max($numbers['left']);
|
$left = max($numbers['left']);
|
||||||
$right = max($numbers['right']);
|
$right = max($numbers['right']);
|
||||||
|
|
||||||
@ -81,7 +104,7 @@ final class Day3 extends Solution
|
|||||||
if ($numbers[0] !== 0 && $numbers[1] === 0 && $numbers[2] !== 0) {
|
if ($numbers[0] !== 0 && $numbers[1] === 0 && $numbers[2] !== 0) {
|
||||||
$result[] = $numbers[0];
|
$result[] = $numbers[0];
|
||||||
$result[] = $numbers[2];
|
$result[] = $numbers[2];
|
||||||
} else {
|
} elseif ($numbers !== []) {
|
||||||
$result[] = max($numbers);
|
$result[] = max($numbers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +150,7 @@ final class Day3 extends Solution
|
|||||||
return $numbers;
|
return $numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNumber(int $row, int $col, string $direction = null): ?string
|
private function getNumber(int $row, int $col, ?string $direction = null): ?string
|
||||||
{
|
{
|
||||||
$number = $this->matrix[$row][$col] ?? null;
|
$number = $this->matrix[$row][$col] ?? null;
|
||||||
|
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace trizz\AdventOfCode\Y23;
|
namespace trizz\AdventOfCode\Y23;
|
||||||
|
|
||||||
final class Day5 extends \trizz\AdventOfCode\Solution
|
use trizz\AdventOfCode\Solution;
|
||||||
|
|
||||||
|
final class Day5 extends Solution
|
||||||
{
|
{
|
||||||
public static null|int|string $part1ExampleResult = 35;
|
public static null|int|string $part1ExampleResult = 35;
|
||||||
|
|
||||||
@ -47,6 +49,10 @@ final class Day5 extends \trizz\AdventOfCode\Solution
|
|||||||
$locations[$seed] = $location;
|
$locations[$seed] = $location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($locations === []) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return min($locations);
|
return min($locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +103,7 @@ final class Day5 extends \trizz\AdventOfCode\Solution
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($line) && !str_contains($line, ':')) {
|
if (!empty($line) && !str_contains($line, ':')) {
|
||||||
[$destinationRange, $sourceRangeStart, $rangeLength] = array_values(array_map('intval', explode(' ', $line)));
|
[$destinationRange, $sourceRangeStart, $rangeLength] = array_map('intval', explode(' ', $line));
|
||||||
$this->maps[$currentMap][] = [
|
$this->maps[$currentMap][] = [
|
||||||
'destinationRange' => $destinationRange,
|
'destinationRange' => $destinationRange,
|
||||||
'sourceRangeStart' => $sourceRangeStart,
|
'sourceRangeStart' => $sourceRangeStart,
|
||||||
|
@ -7,10 +7,14 @@ use trizz\AdventOfCode\Solution;
|
|||||||
final class Day1 extends Solution
|
final class Day1 extends Solution
|
||||||
{
|
{
|
||||||
public static null|int|string $part1ExampleResult = 11;
|
public static null|int|string $part1ExampleResult = 11;
|
||||||
public static null|int|string $part1Result = 1882714;
|
|
||||||
public static null|int|string $part2ExampleResult = 31;
|
|
||||||
public static null|int|string $part2Result = null;
|
|
||||||
|
|
||||||
|
public static null|int|string $part1Result = 1882714;
|
||||||
|
|
||||||
|
public static null|int|string $part2ExampleResult = 31;
|
||||||
|
|
||||||
|
public static null|int|string $part2Result = 19437052;
|
||||||
|
|
||||||
|
#[\Override]
|
||||||
public function part1(array $data): int
|
public function part1(array $data): int
|
||||||
{
|
{
|
||||||
[$listLeft, $listRight] = $this->getList($data);
|
[$listLeft, $listRight] = $this->getList($data);
|
||||||
@ -23,13 +27,14 @@ final class Day1 extends Solution
|
|||||||
return $score;
|
return $score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[\Override]
|
||||||
public function part2(array $data): int
|
public function part2(array $data): int
|
||||||
{
|
{
|
||||||
$score = 0;
|
$score = 0;
|
||||||
[$listLeft, $listRight] = $this->getList($data);
|
[$listLeft, $listRight] = $this->getList($data);
|
||||||
|
|
||||||
foreach ($listLeft as $index => $left) {
|
foreach ($listLeft as $index => $left) {
|
||||||
$right = count(array_filter($listRight, fn ($x) => $x === $left));
|
$right = count(array_filter($listRight, fn ($x): bool => $x === $left));
|
||||||
if ($right > 0) {
|
if ($right > 0) {
|
||||||
$score += $left * $right;
|
$score += $left * $right;
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,3 @@ parameters:
|
|||||||
message: "#^Property trizz\\\\AdventOfCode\\\\Y21\\\\Day8\\:\\:\\$patternDigits type has no value type specified in iterable type array\\.$#"
|
message: "#^Property trizz\\\\AdventOfCode\\\\Y21\\\\Day8\\:\\:\\$patternDigits type has no value type specified in iterable type array\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
path: data/Y21/day8/Day8.php
|
path: data/Y21/day8/Day8.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Method trizz\\\\AdventOfCode\\\\Y23\\\\Day2\\:\\:getHand\\(\\) should return array\\<int, array\\<int, string\\>\\> but returns array\\<int, array\\<int, string\\>\\|string\\>\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: data/Y23/day2/Day2.php
|
|
||||||
|
@ -17,7 +17,7 @@ return static function (RectorConfig $rectorConfig): void {
|
|||||||
// define sets of rules
|
// define sets of rules
|
||||||
$rectorConfig->sets(
|
$rectorConfig->sets(
|
||||||
[
|
[
|
||||||
LevelSetList::UP_TO_PHP_83,
|
LevelSetList::UP_TO_PHP_84,
|
||||||
SetList::CODE_QUALITY,
|
SetList::CODE_QUALITY,
|
||||||
SetList::CODING_STYLE,
|
SetList::CODING_STYLE,
|
||||||
SetList::TYPE_DECLARATION,
|
SetList::TYPE_DECLARATION,
|
||||||
|
@ -78,7 +78,7 @@ abstract class AbstractDayCommand extends Command
|
|||||||
protected function loadClass(): Solution
|
protected function loadClass(): Solution
|
||||||
{
|
{
|
||||||
require_once sprintf('%s/Y%d/day%d/Day%d.php', DATA_DIR, $this->year, $this->day, $this->day);
|
require_once sprintf('%s/Y%d/day%d/Day%d.php', DATA_DIR, $this->year, $this->day, $this->day);
|
||||||
$className = sprintf('%s\\Y%d\\Day%d', substr(__NAMESPACE__, 0, -9), $this->year, $this->day);
|
$className = sprintf('%s\Y%d\Day%d', substr(__NAMESPACE__, 0, -9), $this->year, $this->day);
|
||||||
|
|
||||||
/** @var Solution $class */
|
/** @var Solution $class */
|
||||||
$class = new $className();
|
$class = new $className();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user