Compare commits
2 Commits
108b9ede6b
...
e3481db14f
Author | SHA1 | Date | |
---|---|---|---|
e3481db14f | |||
d3f2406b23 |
14
composer.lock
generated
14
composer.lock
generated
@ -325,16 +325,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nette/php-generator",
|
"name": "nette/php-generator",
|
||||||
"version": "v4.1.6",
|
"version": "v4.1.7",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/nette/php-generator.git",
|
"url": "https://github.com/nette/php-generator.git",
|
||||||
"reference": "c90961e782ae86e517fe5ed732eb2b512945565b"
|
"reference": "d201c9bc217e0969d1b678d286be49302972fb56"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/nette/php-generator/zipball/c90961e782ae86e517fe5ed732eb2b512945565b",
|
"url": "https://api.github.com/repos/nette/php-generator/zipball/d201c9bc217e0969d1b678d286be49302972fb56",
|
||||||
"reference": "c90961e782ae86e517fe5ed732eb2b512945565b",
|
"reference": "d201c9bc217e0969d1b678d286be49302972fb56",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@ -378,7 +378,7 @@
|
|||||||
"homepage": "https://nette.org/contributors"
|
"homepage": "https://nette.org/contributors"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.3 features.",
|
"description": "🐘 Nette PHP Generator: generates neat PHP code for you. Supports new PHP 8.4 features.",
|
||||||
"homepage": "https://nette.org",
|
"homepage": "https://nette.org",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"code",
|
"code",
|
||||||
@ -388,9 +388,9 @@
|
|||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/nette/php-generator/issues",
|
"issues": "https://github.com/nette/php-generator/issues",
|
||||||
"source": "https://github.com/nette/php-generator/tree/v4.1.6"
|
"source": "https://github.com/nette/php-generator/tree/v4.1.7"
|
||||||
},
|
},
|
||||||
"time": "2024-09-10T09:31:55+00:00"
|
"time": "2024-11-29T01:41:18+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "nette/utils",
|
"name": "nette/utils",
|
||||||
|
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