@ 2017-07-12T21:50:39Z <?php
$a1 = [121, 144, 19, 161, 19, 144, 19, 11];
$a2 = [11*11, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19];
var_dump(comp($a1, $a2) === TRUE);
$a1 = [121, 144, 19, 161, 19, 144, 19, 11];
$a2 = [11*21, 121*121, 144*144, 19*19, 161*161, 19*19, 144*144, 19*19];
$a1 = [121, 144, 19, 161, 19, 144, 19, 11];
$a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19];
$a1 = [];
$a2 = [];
$a1 = [];
$a2 = null;
$a1 = [121, 144, 19, 161, 19, 144, 19, 11, 1008];
$a2 = [11*11, 121*121, 144*144, 190*190, 161*161, 19*19, 144*144, 19*19];
$a1 = [10000000, 100000000];
$a2 = [10000000 * 10000000, 100000000 * 100000000];
$a1 = [10000001, 100000000];
$a2 = [10000000 * 10000000, 100000000 * 100000000];
$a1 = [2, 2, 3];
$a2 = [4, 9, 9];
function comp(array $array1 = NULL, array $array2 = NULL) : bool {
$array1 = $array1 ?? [];
$array2 = $array2 ?? [];
$valid_comparison = $array1 !== NULL && $array2 !== NULL ? [[$array1, $array2]] : [];
$valid_comparison = $array1 && $array2 ? [[$array1, $array2]] : [];
$equal_squares = array_reduce($valid_comparison, 'compare_against_squares', false);
return $equal_squares;
}
function compare_against_squares(bool $carry, array $arrays) : bool {
list($array1, $array2) = $arrays;
$array1_squared = array_map('square', $array1);
return compare_sorted_arrays($array1_squared, $array2);
}
function compare_sorted_arrays(array $array1, array $array2) : bool {
sort($array1);
sort($array2);
return $array1 == $array2;
}
function square(int $value) : float {
return $value * $value;
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.0.0 - 7.0.20 , 7.1.0 - 7.1.33 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 bool(true)
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
bool(true)
preferences:dark mode live preview
175.5 ms | 401 KiB | 203 Q