diff options
| author | 2colours <polgar.marton@windowslive.com> | 2024-05-07 13:03:09 +0200 |
|---|---|---|
| committer | 2colours <polgar.marton@windowslive.com> | 2024-05-07 13:03:09 +0200 |
| commit | 89a011ec4944063236e7869f52f56a88e11da769 (patch) | |
| tree | 66b4be7accc4693beba4c8708800a21dbd1ebaea | |
| parent | 8e28c396c7f2d180783b68d047891c2d711e7d50 (diff) | |
| download | perlweeklychallenge-club-89a011ec4944063236e7869f52f56a88e11da769.tar.gz perlweeklychallenge-club-89a011ec4944063236e7869f52f56a88e11da769.tar.bz2 perlweeklychallenge-club-89a011ec4944063236e7869f52f56a88e11da769.zip | |
Weekly solutions in Groovy
| -rw-r--r-- | challenge-268/2colours/groovy/ch-1.groovy | 15 | ||||
| -rw-r--r-- | challenge-268/2colours/groovy/ch-2.groovy | 10 |
2 files changed, 25 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..acaac43654 --- /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 = ').replace(REPLACEMENTS)) +def y = jsonSlurper.parseText(System.console().readLine('@y = ').replace(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..667401cb24 --- /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()) |
