diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-08-10 19:32:00 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-10 19:32:00 +0100 |
| commit | 9a2f222afa54bb5ba5f8bf2a50fa46a6c4ea25a7 (patch) | |
| tree | ae5e9fb607ee6e550c8705a45a3dd92dbb5b9ac3 | |
| parent | ee9090a3d1478e6cf4ab58997a38e20131d6b295 (diff) | |
| parent | 0c160af8677c449edb7a264e638391810a432e53 (diff) | |
| download | perlweeklychallenge-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
| -rw-r--r-- | challenge-020/randy-lauen/perl6/ch-1.p6 | 8 | ||||
| -rw-r--r-- | challenge-020/randy-lauen/perl6/ch-2.p6 | 21 |
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 %% $_ }; +} + |
