From 84d5b5f1015346320fe9a98faabd9ff8652df13b Mon Sep 17 00:00:00 2001 From: 2colours Date: Sat, 11 May 2024 04:09:15 +0200 Subject: PHP solutions for week 262 --- challenge-262/2colours/php/ch-1.php | 7 +++++++ challenge-262/2colours/php/ch-2.php | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 challenge-262/2colours/php/ch-1.php create mode 100644 challenge-262/2colours/php/ch-2.php 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 @@ + 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 @@ + $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 -- cgit From 03929010d2e6003bcc0d8224af773752f3fbffd4 Mon Sep 17 00:00:00 2001 From: 2colours Date: Sun, 12 May 2024 21:09:39 +0200 Subject: Week 262 solutions in Groovy --- challenge-262/2colours/groovy/ch-1.groovy | 6 ++++++ challenge-262/2colours/groovy/ch-2.groovy | 12 ++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 challenge-262/2colours/groovy/ch-1.groovy create mode 100644 challenge-262/2colours/groovy/ch-2.groovy 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 -- cgit From 77244cdd27ba9369ded9f12d06f495f7dab42d2e Mon Sep 17 00:00:00 2001 From: 2colours Date: Sun, 12 May 2024 21:09:56 +0200 Subject: Week #262 solutions in Raku --- challenge-262/2colours/raku/ch-1.raku | 12 ++++++++++++ challenge-262/2colours/raku/ch-2.raku | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 challenge-262/2colours/raku/ch-1.raku create mode 100644 challenge-262/2colours/raku/ch-2.raku 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 /^ '(' * % ',' ')' $/; + +sub MAIN( + $ints +) { + die 'Please provide valid input for @ints' unless $ints.subst(/\s/, '', :g) ~~ IntList; + my Int() @ints = $; + @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 /^ '(' * % ',' ')' $/; + +sub MAIN( + $ints, Int $k +) { + die 'Please provide valid input for @ints' unless $ints.subst(/\s/, '', :g) ~~ IntList; + my Int() @ints = $; + @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 -- cgit