aboutsummaryrefslogtreecommitdiff
path: root/challenge-020
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-08-10 19:32:00 +0100
committerGitHub <noreply@github.com>2019-08-10 19:32:00 +0100
commit9a2f222afa54bb5ba5f8bf2a50fa46a6c4ea25a7 (patch)
treeae5e9fb607ee6e550c8705a45a3dd92dbb5b9ac3 /challenge-020
parentee9090a3d1478e6cf4ab58997a38e20131d6b295 (diff)
parent0c160af8677c449edb7a264e638391810a432e53 (diff)
downloadperlweeklychallenge-club-9a2f222afa54bb5ba5f8bf2a50fa46a6c4ea25a7.tar.gz
perlweeklychallenge-club-9a2f222afa54bb5ba5f8bf2a50fa46a6c4ea25a7.tar.bz2
perlweeklychallenge-club-9a2f222afa54bb5ba5f8bf2a50fa46a6c4ea25a7.zip
Merge pull request #488 from randyl/week20
Solutions for challenge 1 and 2
Diffstat (limited to 'challenge-020')
-rw-r--r--challenge-020/randy-lauen/perl6/ch-1.p68
-rw-r--r--challenge-020/randy-lauen/perl6/ch-2.p621
2 files changed, 29 insertions, 0 deletions
diff --git a/challenge-020/randy-lauen/perl6/ch-1.p6 b/challenge-020/randy-lauen/perl6/ch-1.p6
new file mode 100644
index 0000000000..5c23588b8c
--- /dev/null
+++ b/challenge-020/randy-lauen/perl6/ch-1.p6
@@ -0,0 +1,8 @@
+#!/usr/bin/env perl6
+
+# Write a script to accept a string from command line and split it on change of character.
+# For example, if the string is “ABBCDEEF”, then it should split like “A”, “BB”, “C”, “D”, “EE”, “F”.
+
+sub MAIN( Str $text ) {
+ say $text.comb(/(.) {} $0*/).join(',');
+}
diff --git a/challenge-020/randy-lauen/perl6/ch-2.p6 b/challenge-020/randy-lauen/perl6/ch-2.p6
new file mode 100644
index 0000000000..1cd638e758
--- /dev/null
+++ b/challenge-020/randy-lauen/perl6/ch-2.p6
@@ -0,0 +1,21 @@
+#!/usr/bin/env perl6
+
+# Write a script to print the smallest pair of Amicable Numbers.
+
+say amicable-numbers.first;
+
+sub amicable-numbers {
+ return lazy gather {
+ my %seen;
+ for 1 .. Inf -> $i {
+ my $key = ($i, sum proper-divisors( $i )).sort.join(',');
+ take $key if %seen{ $key }:exists;
+ %seen{ $key } = 1;
+ }
+ };
+}
+
+sub proper-divisors( $i ) {
+ return (1 .. $i-1).grep: { $i %% $_ };
+}
+