Compare commits

..

4 Commits

Author SHA1 Message Date
7a594d4c2e Update symfony packages to v7.2.0
Some checks failed
renovate/artifacts Artifact file update failure
2024-11-30 00:00:40 +00:00
a74543deb4 Update dependency pestphp/pest to v3 2024-11-26 07:50:38 +00:00
a7cf04051e Update php Docker tag to v8.4 2024-11-26 08:50:06 +01:00
4b5489d1c8 Update dependency laravel/prompts to ^0.3.0 2024-11-26 00:00:42 +00:00
6 changed files with 456 additions and 1637 deletions

View File

@ -9,28 +9,28 @@ steps:
- composer install
- name: phpstan
image: php:8.3
image: php:8.4
depends_on:
- install
commands:
- vendor/bin/phpstan analyse
- name: rector
image: php:8.3
image: php:8.4
depends_on:
- install
commands:
- vendor/bin/rector process --dry-run
- name: pest
image: php:8.3
image: php:8.4
depends_on:
- install
commands:
- vendor/bin/pest
- name: style check
image: php:8.3
image: php:8.4
depends_on:
- install
commands:

View File

@ -16,7 +16,7 @@
"laravel/prompts": "^0.1.13",
"nette/php-generator": "^4.1",
"phppkg/cli-markdown": "^2.0",
"symfony/console": "^7"
"symfony/console": "^6"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.3",
@ -30,7 +30,7 @@
},
"autoload": {
"psr-4": {
"trizz\\AdventOfCode\\": "src/"
"trizz\\AdventOfCode\\": "src-php/"
}
},
"autoload-dev": {

1012
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,61 +0,0 @@
<?php
namespace trizz\AdventOfCode\Y24;
use trizz\AdventOfCode\Solution;
final class Day1 extends Solution
{
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 function part1(array $data): int
{
[$listLeft, $listRight] = $this->getList($data);
$score = 0;
foreach ($listLeft as $index => $left) {
$right = $listRight[$index];
$score += abs($left - $right);
}
return $score;
}
public function part2(array $data): int
{
$score = 0;
[$listLeft, $listRight] = $this->getList($data);
foreach ($listLeft as $index => $left) {
$right = count(array_filter($listRight, fn ($x) => $x === $left));
if ($right > 0) {
$score += $left * $right;
}
}
return $score;
}
/**
* @param array<int,string> $data
*
* @return array<int,int[]>
*/
private function getList(array $data): array
{
$listLeft = [];
$listRight = [];
foreach ($data as $x) {
[$a1, $_, $_, $b1] = explode(' ', $x);
$listLeft[] = (int) $a1;
$listRight[] = (int) $b1;
}
sort($listLeft);
sort($listRight);
return [$listLeft, $listRight];
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
3 4
4 3
2 5
1 3
3 9
3 3