})(['summer', 'winter', 'spring', 'autumn']));
}
-function closest($n, $list) {
- $a = array_filter($list, function($value) use ($n) {
- return $value <= $n;
- });
+function closestIndex($n, array $list) {
+ //return $list[closestIndex($n, $list)];
+ $a = map(function(int $v) use ($n) : int {
+ return (int)abs($v - $n);
+ })
+ ($list);
- arsort($a);
- return array_values($a)[0];
+ asort($a);
+ return array_keys($a)[0];
+}
+
+function closest($n, array $list) : int {
+ return $list[closestIndex($n, $list)];
}
function reveal($str) {
$penultimateBytes = array_filter(
(unpack('C*', $str)),
function($key) {
- return ($key + 1) % 4 == 0;
+ return ($key + 1) % 4 ==
+ 0;
},
ARRAY_FILTER_USE_KEY
);