aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-12-18 07:53:23 +0000
committerGitHub <noreply@github.com>2022-12-18 07:53:23 +0000
commit4796777b1b75a4e0551175f6345695a96d37ca98 (patch)
tree7f77cc0b2d632cd013b17aa8adba153ae8ecff15
parent78310ab18f608d99867c2133d8567de288bd00ee (diff)
parent571389cf630a6fc1d05bee5b87689c2d282b4598 (diff)
downloadperlweeklychallenge-club-4796777b1b75a4e0551175f6345695a96d37ca98.tar.gz
perlweeklychallenge-club-4796777b1b75a4e0551175f6345695a96d37ca98.tar.bz2
perlweeklychallenge-club-4796777b1b75a4e0551175f6345695a96d37ca98.zip
Merge pull request #7267 from 2colours/branch-for-challenge-195
Current weeklies by 2colours
-rwxr-xr-xchallenge-195/2colours/raku/ch-1.raku29
-rwxr-xr-xchallenge-195/2colours/raku/ch-2.raku15
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-195/2colours/raku/ch-1.raku b/challenge-195/2colours/raku/ch-1.raku
new file mode 100755
index 0000000000..12c3887e72
--- /dev/null
+++ b/challenge-195/2colours/raku/ch-1.raku
@@ -0,0 +1,29 @@
+#!/usr/bin/env raku
+
+subset PosInt of Int where * > 0;
+
+multi count-special-until(PosInt $max) {
+ samewith .chars, .comb, '0' .. '9', :first-digit given $max
+}
+
+multi count-special-until(1, @max, Set() $not-used, Bool :$first-digit = False --> PosInt) {
+ $not-used.keys.grep({ not $_ after @max.head || $first-digit && $_ eq '0' }).elems
+}
+
+multi count-special-until(PosInt $digits, @max, Set() $not-used, Bool :$first-digit = False --> Int) {
+ my $classified = $not-used.keys.classify(* cmp @max[0]);
+ my Set() $less = $classified{Less} // Empty;
+ $less (-)= '0' if $first-digit;
+ my Set() $same = $classified{Same} // Empty;
+ my $result = 0;
+ $result += samewith($digits - 1, [ ** ], $not-used, :first-digit) if $first-digit;
+ $result += $less * samewith($digits - 1, [ ** ], $not-used (-) $less.keys[0]) if $less > 0; # doesn't matter for the calculation which digit is marked as used
+ $result += samewith($digits - 1, @max.skip, $not-used (-) $same.keys[0]) if $same;
+ $result
+}
+
+sub MAIN(
+ PosInt $n #= upper limit for counting special numbers
+) {
+ $n.&count-special-until.say;
+}
diff --git a/challenge-195/2colours/raku/ch-2.raku b/challenge-195/2colours/raku/ch-2.raku
new file mode 100755
index 0000000000..451a94d037
--- /dev/null
+++ b/challenge-195/2colours/raku/ch-2.raku
@@ -0,0 +1,15 @@
+#!/usr/bin/env raku
+
+my token integer { 0 | '-'? <[1..9]> <[0..9]>* }
+subset IntList of Str where /^ '(' <integer>* % ',' ')' $/; # The task didn't specify what a "list of numbers" should be - treating it as a list of integers
+
+sub MAIN(
+ $list #= list of integer numbers
+) {
+ die 'Please provide valid input for @list' unless $list.subst(/\s/, '', :g) ~~ IntList;
+ my Int() @list = $<integer>;
+ @list.grep(* %% 2).Bag andthen
+ .so ?? .max({ .value, - .key }).key !! -1 andthen
+ .say;
+
+}