aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author2colours <polgar.marton@windowslive.com>2024-05-12 21:09:39 +0200
committer2colours <polgar.marton@windowslive.com>2024-05-12 21:09:39 +0200
commit03929010d2e6003bcc0d8224af773752f3fbffd4 (patch)
treeb89cdcf4bb3bdc6d7e141f4dc5a0ced62db04eeb
parent84d5b5f1015346320fe9a98faabd9ff8652df13b (diff)
downloadperlweeklychallenge-club-03929010d2e6003bcc0d8224af773752f3fbffd4.tar.gz
perlweeklychallenge-club-03929010d2e6003bcc0d8224af773752f3fbffd4.tar.bz2
perlweeklychallenge-club-03929010d2e6003bcc0d8224af773752f3fbffd4.zip
Week 262 solutions in Groovy
-rw-r--r--challenge-262/2colours/groovy/ch-1.groovy6
-rw-r--r--challenge-262/2colours/groovy/ch-2.groovy12
2 files changed, 18 insertions, 0 deletions
diff --git a/challenge-262/2colours/groovy/ch-1.groovy b/challenge-262/2colours/groovy/ch-1.groovy
new file mode 100644
index 0000000000..bd1b79407a
--- /dev/null
+++ b/challenge-262/2colours/groovy/ch-1.groovy
@@ -0,0 +1,6 @@
+import groovy.json.JsonSlurper
+
+final REPLACEMENTS = ['()', '[]']
+def jsonSlurper = new JsonSlurper()
+def ints = jsonSlurper.parseText(System.console().readLine('@ints = ').tr(*REPLACEMENTS))
+println ints.groupBy{ Integer.signum(it) }.findAll{ it.key.abs() > 0 }.values()*.size().max() \ No newline at end of file
diff --git a/challenge-262/2colours/groovy/ch-2.groovy b/challenge-262/2colours/groovy/ch-2.groovy
new file mode 100644
index 0000000000..2aa51bd176
--- /dev/null
+++ b/challenge-262/2colours/groovy/ch-2.groovy
@@ -0,0 +1,12 @@
+import groovy.json.JsonSlurper
+
+final REPLACEMENTS = ['()', '[]']
+def jsonSlurper = new JsonSlurper()
+def ints = jsonSlurper.parseText(System.console().readLine('@ints = ').tr(*REPLACEMENTS))
+def k = System.console().readLine('$k = ').toInteger()
+println ints.withIndex().collect { it, index ->
+ Integer neededFactor = k / (k as BigInteger).gcd(index as BigInteger)
+ Integer nextValid = Math.ceil((index + 1) / neededFactor) * neededFactor;
+ def possible_values = ints.drop(nextValid).collate(neededFactor)*.get(0)
+ possible_values.count(it)
+}.sum() \ No newline at end of file