aboutsummaryrefslogtreecommitdiff
path: root/challenge-065
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2020-06-20 14:07:07 +0100
committerGitHub <noreply@github.com>2020-06-20 14:07:07 +0100
commit6576a2028549fde22a0ea558b6fae3a79371ccfb (patch)
tree6592602fa41789167ca8ebd072507b90880ab9ec /challenge-065
parentb5e96df160c483ff59d3fe6fce96f45b58b5fa8d (diff)
parent26346e24c899eb118c132cc3729a6381967e052a (diff)
downloadperlweeklychallenge-club-6576a2028549fde22a0ea558b6fae3a79371ccfb.tar.gz
perlweeklychallenge-club-6576a2028549fde22a0ea558b6fae3a79371ccfb.tar.bz2
perlweeklychallenge-club-6576a2028549fde22a0ea558b6fae3a79371ccfb.zip
Merge pull request #1838 from andemark/branch-for-challenge-065
Challenge 65 Solutions
Diffstat (limited to 'challenge-065')
-rw-r--r--challenge-065/mark-anderson/raku/ch-1.raku26
-rw-r--r--challenge-065/mark-anderson/raku/ch-2.raku41
2 files changed, 67 insertions, 0 deletions
diff --git a/challenge-065/mark-anderson/raku/ch-1.raku b/challenge-065/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..2032db6abf
--- /dev/null
+++ b/challenge-065/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,26 @@
+#!/usr/bin/env raku
+
+# Usage:
+# raku ch-1.raku 4 8
+
+# Output:
+# 1007 1016 1025 1034 1043 1052 1061 1070 1106 1115
+# 1124 1133 1142 1151 1160 1205 1214 1223 1232 1241
+# 1250 1304 1313 1322 1331 1340 1403 1412 1421 1430
+# 1502 1511 1520 1601 1610 1700 2006 2015 2024 2033
+# 2042 2051 2060 2105 2114 2123 2132 2141 2150 2204
+# 2213 2222 2231 2240 2303 2312 2321 2330 2402 2411
+# 2420 2501 2510 2600 3005 3014 3023 3032 3041 3050
+# 3104 3113 3122 3131 3140 3203 3212 3221 3230 3302
+# 3311 3320 3401 3410 3500 4004 4013 4022 4031 4040
+# 4103 4112 4121 4130 4202 4211 4220 4301 4310 4400
+# 5003 5012 5021 5030 5102 5111 5120 5201 5210 5300
+# 6002 6011 6020 6101 6110 6200 7001 7010 7100 8000
+
+sub MAIN(UInt $N, UInt $S) {
+ say (10**($N-1)..(10**$N)-1).map(*.comb.cache)
+ .grep(*.sum == $S)
+ .map(*.join)
+ .rotor(10, :partial)
+ .fmt("%d", "\n");
+}
diff --git a/challenge-065/mark-anderson/raku/ch-2.raku b/challenge-065/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..9aa751f0b3
--- /dev/null
+++ b/challenge-065/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,41 @@
+#!/usr/bin/env raku
+
+# Usage:
+# raku ch-2.raku aabbababba
+
+# Output:
+# aa bbababb
+# bb aba bb
+# abbababba
+# abba bab
+# babab
+# bab abba
+
+my @matches;
+
+sub MAIN(Str $str) {
+ @matches = gather ($str ~~ m:ex /(\w ** 2..*) <?{ $0 eq $0.flip }>/)>>.take;
+
+ partition([$_]) for @matches;
+}
+
+sub partition(@arr) {
+ state %seen;
+
+ my $match = @arr[*-1];
+
+ unless %seen{$match.from ~ " " ~ $match.to}:exists {
+ %seen{$match.from ~ " " ~ $match.to} = 1;
+
+ my @m = @matches.grep($match.to == *.from);
+
+ if @m {
+ partition(@arr.push: $_) for @m;
+ }
+
+ else {
+ say @arr>>.flat.Str;
+ @arr = Empty;
+ }
+ }
+}