diff options
| -rw-r--r-- | challenge-268/2colours/php/ch-1.php | 18 | ||||
| -rw-r--r-- | challenge-268/2colours/php/ch-2.php | 10 |
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-268/2colours/php/ch-1.php b/challenge-268/2colours/php/ch-1.php new file mode 100644 index 0000000000..789c278b98 --- /dev/null +++ b/challenge-268/2colours/php/ch-1.php @@ -0,0 +1,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'; diff --git a/challenge-268/2colours/php/ch-2.php b/challenge-268/2colours/php/ch-2.php new file mode 100644 index 0000000000..2526cd6f61 --- /dev/null +++ b/challenge-268/2colours/php/ch-2.php @@ -0,0 +1,10 @@ +<?php + +const PARENS = ['(', ')']; +const BRACKETS = ['[', ']']; +echo '@ints = '; +$ints = json_decode(str_replace(PARENS, BRACKETS, fgets(STDIN))); + +sort($ints); + +echo str_replace(BRACKETS, PARENS, json_encode(array_merge(...array_map(array_reverse(...), array_chunk($ints, 2))))); |
