diff options
| author | 2colours <polgar.marton@windowslive.com> | 2024-05-07 13:02:55 +0200 |
|---|---|---|
| committer | 2colours <polgar.marton@windowslive.com> | 2024-05-07 13:02:55 +0200 |
| commit | 8e28c396c7f2d180783b68d047891c2d711e7d50 (patch) | |
| tree | e6134343465af6f6f0d7f04767a90c00dc8ec87f /challenge-268 | |
| parent | 479ca4e9c71aa2ea5be2bc7b66451c21be9d8dde (diff) | |
| download | perlweeklychallenge-club-8e28c396c7f2d180783b68d047891c2d711e7d50.tar.gz perlweeklychallenge-club-8e28c396c7f2d180783b68d047891c2d711e7d50.tar.bz2 perlweeklychallenge-club-8e28c396c7f2d180783b68d047891c2d711e7d50.zip | |
Weekly solutions in PHP
Diffstat (limited to 'challenge-268')
| -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))))); |
