aboutsummaryrefslogtreecommitdiff
path: root/challenge-268/2colours/php/ch-1.php
blob: 789c278b9882e976bd377c1e1f0f188009b89fba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php


const PARENS = ['(', ')'];
const BRACKETS = ['[', ']'];
echo '@x = ';
$x = json_decode(str_replace(PARENS, BRACKETS, fgets(STDIN)));
echo '@y = ';
$y = json_decode(str_replace(PARENS, BRACKETS, fgets(STDIN)));

sort($x);
sort($y);

$expected_difference = $y[0] - $x[0];

$all_expected = array_product(array_map(fn($a, $b) => $b - $a === $expected_difference, $x, $y));

echo $all_expected ? $expected_difference : 'N/A';