diff options
| -rw-r--r-- | challenge-262/2colours/groovy/ch-1.groovy | 6 | ||||
| -rw-r--r-- | challenge-262/2colours/groovy/ch-2.groovy | 12 |
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 |
