✨ Finit le jour 3
This commit is contained in:
parent
dafbffbcf8
commit
1e84b70b7a
15
day_3/part_1.php
Normal file
15
day_3/part_1.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$rucksacks = explode("\n", file_get_contents('./input.txt'));
|
||||||
|
|
||||||
|
$lettersToNumbers = array_merge(range('a', 'z'), range('A', 'Z'));
|
||||||
|
|
||||||
|
echo array_sum(
|
||||||
|
array_map(
|
||||||
|
static function($rucksack) use ($lettersToNumbers) {
|
||||||
|
[$f, $s] = array_map('str_split', str_split($rucksack, strlen($rucksack)/2));
|
||||||
|
return array_search(current(array_intersect($f, $s)), $lettersToNumbers, true) + 1;
|
||||||
|
},
|
||||||
|
$rucksacks
|
||||||
|
)
|
||||||
|
);
|
17
day_3/part_2.php
Normal file
17
day_3/part_2.php
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
$rucksacks = explode("\n", file_get_contents('./input.txt'));
|
||||||
|
|
||||||
|
$lettersToNumbers = array_merge(range('a', 'z'), range('A', 'Z'));
|
||||||
|
|
||||||
|
$groups = array_chunk($rucksacks, 3);
|
||||||
|
|
||||||
|
echo array_sum(
|
||||||
|
array_map(
|
||||||
|
static function($rucksacks) use ($lettersToNumbers) {
|
||||||
|
[$f, $s, $t] = array_map('str_split', $rucksacks);
|
||||||
|
return array_search(current(array_intersect($f, $s, $t)), $lettersToNumbers, true) + 1;
|
||||||
|
},
|
||||||
|
$groups
|
||||||
|
)
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user