aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-268/2colours/groovy/ch-1.groovy15
-rw-r--r--challenge-268/2colours/groovy/ch-2.groovy10
-rw-r--r--challenge-268/2colours/php/ch-1.php18
-rw-r--r--challenge-268/2colours/php/ch-2.php10
4 files changed, 53 insertions, 0 deletions
diff --git a/challenge-268/2colours/groovy/ch-1.groovy b/challenge-268/2colours/groovy/ch-1.groovy
new file mode 100644
index 0000000000..385e3f776f
--- /dev/null
+++ b/challenge-268/2colours/groovy/ch-1.groovy
@@ -0,0 +1,15 @@
+import groovy.json.JsonSlurper
+
+final REPLACEMENTS = ['()', '[]']
+def jsonSlurper = new JsonSlurper()
+def x = jsonSlurper.parseText(System.console().readLine('@x = ').tr(*REPLACEMENTS))
+def y = jsonSlurper.parseText(System.console().readLine('@y = ').tr(*REPLACEMENTS))
+
+x.sort()
+y.sort()
+
+def expected_difference = y[0] - x[0]
+
+def all_expected = [x, y].transpose().collect{ a, b -> b - a }.every{ it == expected_difference }
+
+println all_expected ? expected_difference : 'N/A'
diff --git a/challenge-268/2colours/groovy/ch-2.groovy b/challenge-268/2colours/groovy/ch-2.groovy
new file mode 100644
index 0000000000..5f679e77ac
--- /dev/null
+++ b/challenge-268/2colours/groovy/ch-2.groovy
@@ -0,0 +1,10 @@
+import groovy.json.JsonSlurper
+import groovy.json.JsonOutput
+
+final REPLACEMENTS = ['()', '[]']
+def jsonSlurper = new JsonSlurper()
+def ints = jsonSlurper.parseText(System.console().readLine('@ints = ').tr(*REPLACEMENTS))
+
+ints.sort()
+
+println JsonOutput.toJson(ints.collate(2).collectMany{ it.reverse() }).tr(*REPLACEMENTS.reverse())
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)))));