20 lines
409 B
PHP
20 lines
409 B
PHP
<?php
|
|
|
|
$list_1 = [];
|
|
$list_2 = [];
|
|
|
|
$lines = array_filter(explode("\n", file_get_contents(__DIR__.'/input.txt')), static fn($line) =>!empty($line));
|
|
|
|
foreach ($lines as $line) {
|
|
[$a, $b] = explode(" ", $line);
|
|
$list_1[] = $a;
|
|
$list_2[] = $b;
|
|
}
|
|
|
|
sort($list_1); sort($list_2);
|
|
$total = 0;
|
|
for ($i=0, $l=count($list_1); $i < $l; $i++) {
|
|
$total += abs($list_1[$i] - $list_2[$i]);
|
|
}
|
|
|
|
echo $total; |