aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-05-13 00:32:17 +0100
committerGitHub <noreply@github.com>2024-05-13 00:32:17 +0100
commit2fd5134e36c0e93e2db8677341b5a064e119d5c6 (patch)
tree59aa7829fe1e7962628bf7617c20d1d0b87cd7c1
parent7f79fc198fbb406bf7b29b4725e01346910248bb (diff)
parent77244cdd27ba9369ded9f12d06f495f7dab42d2e (diff)
downloadperlweeklychallenge-club-2fd5134e36c0e93e2db8677341b5a064e119d5c6.tar.gz
perlweeklychallenge-club-2fd5134e36c0e93e2db8677341b5a064e119d5c6.tar.bz2
perlweeklychallenge-club-2fd5134e36c0e93e2db8677341b5a064e119d5c6.zip
Merge pull request #10079 from 2colours/branch-for-challenge-262
Branch for challenge 262
-rw-r--r--challenge-262/2colours/groovy/ch-1.groovy6
-rw-r--r--challenge-262/2colours/groovy/ch-2.groovy12
-rw-r--r--challenge-262/2colours/php/ch-1.php7
-rw-r--r--challenge-262/2colours/php/ch-2.php16
-rw-r--r--challenge-262/2colours/raku/ch-1.raku12
-rw-r--r--challenge-262/2colours/raku/ch-2.raku16
6 files changed, 69 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
diff --git a/challenge-262/2colours/php/ch-1.php b/challenge-262/2colours/php/ch-1.php
new file mode 100644
index 0000000000..c714bc2363
--- /dev/null
+++ b/challenge-262/2colours/php/ch-1.php
@@ -0,0 +1,7 @@
+<?php
+
+const PARENS = ['(', ')'];
+const SQUARE_BRACKETS = ['[', ']'];
+echo '@ints = ';
+$ints = json_decode(str_replace(PARENS, SQUARE_BRACKETS, fgets(STDIN)));
+echo max(...array_map(fn ($pred) => count(array_filter($ints, $pred)), [fn ($x) => $x > 0, fn ($x) => $x < 0])); \ No newline at end of file
diff --git a/challenge-262/2colours/php/ch-2.php b/challenge-262/2colours/php/ch-2.php
new file mode 100644
index 0000000000..bec9137694
--- /dev/null
+++ b/challenge-262/2colours/php/ch-2.php
@@ -0,0 +1,16 @@
+<?php
+
+const PARENS = ['(', ')'];
+const SQUARE_BRACKETS = ['[', ']'];
+echo '@ints = ';
+$ints = json_decode(str_replace(PARENS, SQUARE_BRACKETS, fgets(STDIN)));
+echo '$k = ';
+$k = fgets(STDIN);
+$result = 0;
+foreach ($ints as $index => $value) {
+ $needed_factor = intdiv($k, gmp_intval(gmp_gcd($index, $k)));
+ $next_valid = ceil(($index + 1) / $needed_factor) * $needed_factor;
+ $values_to_check = array_column(array_chunk(array_slice($ints, $next_valid), $needed_factor), 0);
+ $result += @array_count_values($values_to_check)[$value];
+}
+echo $result; \ No newline at end of file
diff --git a/challenge-262/2colours/raku/ch-1.raku b/challenge-262/2colours/raku/ch-1.raku
new file mode 100644
index 0000000000..b574e442b8
--- /dev/null
+++ b/challenge-262/2colours/raku/ch-1.raku
@@ -0,0 +1,12 @@
+#!/usr/bin/env raku
+
+my token integer { 0 | '-'? <[1..9]> <[0..9]>* }
+subset IntList of Str where /^ '(' <integer>* % ',' ')' $/;
+
+sub MAIN(
+ $ints
+) {
+ die 'Please provide valid input for @ints' unless $ints.subst(/\s/, '', :g) ~~ IntList;
+ my Int() @ints = $<integer>;
+ @ints.grep(* != 0).classify(*.sign).map(*.value.elems).max.say;
+} \ No newline at end of file
diff --git a/challenge-262/2colours/raku/ch-2.raku b/challenge-262/2colours/raku/ch-2.raku
new file mode 100644
index 0000000000..95733dc291
--- /dev/null
+++ b/challenge-262/2colours/raku/ch-2.raku
@@ -0,0 +1,16 @@
+#!/usr/bin/env raku
+
+my token integer { 0 | '-'? <[1..9]> <[0..9]>* }
+subset IntList of Str where /^ '(' <integer>* % ',' ')' $/;
+
+sub MAIN(
+ $ints, Int $k
+) {
+ die 'Please provide valid input for @ints' unless $ints.subst(/\s/, '', :g) ~~ IntList;
+ my Int() @ints = $<integer>;
+ @ints.kv.map(-> $index, $value {
+ my $needed-factor = $k div ($k gcd $index);
+ my $next-valid = ceiling(($index + 1) / $needed-factor) * $needed-factor;
+ @ints[$next-valid, $next-valid + $needed-factor ...^ @ints.elems].grep($value).elems
+ }).sum.say;
+} \ No newline at end of file