From 86a9a89590151c9cc7af96784bcf470a4a11a8d8 Mon Sep 17 00:00:00 2001 From: Randy Lauen Date: Sun, 4 Aug 2019 22:38:12 -0500 Subject: solution for challenge 1 --- challenge-020/randy-lauen/ch-1.p6 | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 challenge-020/randy-lauen/ch-1.p6 diff --git a/challenge-020/randy-lauen/ch-1.p6 b/challenge-020/randy-lauen/ch-1.p6 new file mode 100644 index 0000000000..28c4e8c325 --- /dev/null +++ b/challenge-020/randy-lauen/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.match( /((.) {} $0*)*/ ).flat>>.Str.join(","); +} -- cgit From c098bc186f9eaf7f33fc4a9afca53dacf872f93b Mon Sep 17 00:00:00 2001 From: Randy Lauen Date: Mon, 5 Aug 2019 21:33:07 -0500 Subject: move file into correct directory --- challenge-020/randy-lauen/ch-1.p6 | 8 -------- challenge-020/randy-lauen/perl6/ch-1.p6 | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) delete mode 100644 challenge-020/randy-lauen/ch-1.p6 create mode 100644 challenge-020/randy-lauen/perl6/ch-1.p6 diff --git a/challenge-020/randy-lauen/ch-1.p6 b/challenge-020/randy-lauen/ch-1.p6 deleted file mode 100644 index 28c4e8c325..0000000000 --- a/challenge-020/randy-lauen/ch-1.p6 +++ /dev/null @@ -1,8 +0,0 @@ -#!/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.match( /((.) {} $0*)*/ ).flat>>.Str.join(","); -} 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..28c4e8c325 --- /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.match( /((.) {} $0*)*/ ).flat>>.Str.join(","); +} -- cgit From 21bcfd2e2daba18a447040a6f70d7dde76e7dad6 Mon Sep 17 00:00:00 2001 From: Randy Lauen Date: Fri, 9 Aug 2019 17:42:00 -0500 Subject: simplify using .comb --- challenge-020/randy-lauen/perl6/ch-1.p6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-020/randy-lauen/perl6/ch-1.p6 b/challenge-020/randy-lauen/perl6/ch-1.p6 index 28c4e8c325..5c23588b8c 100644 --- a/challenge-020/randy-lauen/perl6/ch-1.p6 +++ b/challenge-020/randy-lauen/perl6/ch-1.p6 @@ -4,5 +4,5 @@ # For example, if the string is “ABBCDEEF”, then it should split like “A”, “BB”, “C”, “D”, “EE”, “F”. sub MAIN( Str $text ) { - say $text.match( /((.) {} $0*)*/ ).flat>>.Str.join(","); + say $text.comb(/(.) {} $0*/).join(','); } -- cgit From 0c160af8677c449edb7a264e638391810a432e53 Mon Sep 17 00:00:00 2001 From: Randy Lauen Date: Fri, 9 Aug 2019 17:42:16 -0500 Subject: solution for challenge 2 --- challenge-020/randy-lauen/perl6/ch-2.p6 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 challenge-020/randy-lauen/perl6/ch-2.p6 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 %% $_ }; +} + -- cgit