Compare commits

...

2 Commits

Author SHA1 Message Date
f7034908f9 Update dependency phpstan/phpstan to v1.12.12 2024-12-01 10:10:41 +00:00
d3f2406b23
Add day 1 '24 2024-12-01 11:04:30 +01:00
4 changed files with 1074 additions and 5 deletions

10
composer.lock generated
View File

@ -3041,16 +3041,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "1.12.11", "version": "1.12.12",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733" "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0",
"reference": "0d1fc20a962a91be578bcfe7cf939e6e1a2ff733", "reference": "b5ae1b88f471d3fd4ba1aa0046234b5ca3776dd0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3095,7 +3095,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2024-11-17T14:08:01+00:00" "time": "2024-11-28T22:13:23+00:00"
}, },
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",

61
data/Y24/day1/Day1.php Normal file
View 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

File diff suppressed because it is too large Load Diff

View File

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