Compare commits
2 Commits
d4fbe363d7
...
f7034908f9
Author | SHA1 | Date | |
---|---|---|---|
f7034908f9 | |||
d3f2406b23 |
@ -9,28 +9,28 @@ steps:
|
|||||||
- composer install
|
- composer install
|
||||||
|
|
||||||
- name: phpstan
|
- name: phpstan
|
||||||
image: php:8.4
|
image: php:8.3
|
||||||
depends_on:
|
depends_on:
|
||||||
- install
|
- install
|
||||||
commands:
|
commands:
|
||||||
- vendor/bin/phpstan analyse
|
- vendor/bin/phpstan analyse
|
||||||
|
|
||||||
- name: rector
|
- name: rector
|
||||||
image: php:8.4
|
image: php:8.3
|
||||||
depends_on:
|
depends_on:
|
||||||
- install
|
- install
|
||||||
commands:
|
commands:
|
||||||
- vendor/bin/rector process --dry-run
|
- vendor/bin/rector process --dry-run
|
||||||
|
|
||||||
- name: pest
|
- name: pest
|
||||||
image: php:8.4
|
image: php:8.3
|
||||||
depends_on:
|
depends_on:
|
||||||
- install
|
- install
|
||||||
commands:
|
commands:
|
||||||
- vendor/bin/pest
|
- vendor/bin/pest
|
||||||
|
|
||||||
- name: style check
|
- name: style check
|
||||||
image: php:8.4
|
image: php:8.3
|
||||||
depends_on:
|
depends_on:
|
||||||
- install
|
- install
|
||||||
commands:
|
commands:
|
||||||
|
@ -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.3.0",
|
"laravel/prompts": "^0.1.13",
|
||||||
"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,7 +22,7 @@
|
|||||||
"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": "^3.0",
|
"pestphp/pest": "^2.26",
|
||||||
"phpstan/phpstan": "^1.2",
|
"phpstan/phpstan": "^1.2",
|
||||||
"rector/rector": "^1.0",
|
"rector/rector": "^1.0",
|
||||||
"robiningelbrecht/phpunit-pretty-print": "^1.2",
|
"robiningelbrecht/phpunit-pretty-print": "^1.2",
|
||||||
|
954
composer.lock
generated
954
composer.lock
generated
File diff suppressed because it is too large
Load Diff
61
data/Y24/day1/Day1.php
Normal file
61
data/Y24/day1/Day1.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?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];
|
||||||
|
}
|
||||||
|
}
|
1001
data/Y24/day1/data.txt
Normal file
1001
data/Y24/day1/data.txt
Normal file
File diff suppressed because it is too large
Load Diff
7
data/Y24/day1/example.txt
Normal file
7
data/Y24/day1/example.txt
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
3 4
|
||||||
|
4 3
|
||||||
|
2 5
|
||||||
|
1 3
|
||||||
|
3 9
|
||||||
|
3 3
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user