✨ Finit le jour 2 et commence le 1 et le 3
This commit is contained in:
18
day_3/part_1.php
Normal file
18
day_3/part_1.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
$banks = explode("\n", file_get_contents('./input.txt'));
|
||||
|
||||
$output_joltage = [];
|
||||
|
||||
foreach ($banks as $bank) {
|
||||
$a_bank = str_split($bank);
|
||||
|
||||
$max = max(array_slice($a_bank,0,count($a_bank)-1));
|
||||
$i = array_search($max, $a_bank);
|
||||
$right_part = array_slice($a_bank, $i+1);
|
||||
$max2 = max($right_part);
|
||||
|
||||
$output_joltage[] = (int) $max.$max2;
|
||||
}
|
||||
|
||||
echo array_sum($output_joltage);
|
||||
Reference in New Issue
Block a user