diff options
| -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 %% $_ }; +} + |
