diff options
| author | Ryan Thompson <i@ry.ca> | 2019-12-23 02:21:25 -0600 |
|---|---|---|
| committer | Ryan Thompson <i@ry.ca> | 2019-12-23 02:21:25 -0600 |
| commit | 3101d00a9c62d8ccc9f62d58c7be516cbce712f4 (patch) | |
| tree | 59abc8a780ca08891e1e906a4ac631a62e185f7d /challenge-006/ryan-thompson | |
| parent | 2033c83ccafc6a44d65153209fea390e44200d4d (diff) | |
| download | perlweeklychallenge-club-3101d00a9c62d8ccc9f62d58c7be516cbce712f4.tar.gz perlweeklychallenge-club-3101d00a9c62d8ccc9f62d58c7be516cbce712f4.tar.bz2 perlweeklychallenge-club-3101d00a9c62d8ccc9f62d58c7be516cbce712f4.zip | |
Solutions for 006 and 007.1
Diffstat (limited to 'challenge-006/ryan-thompson')
| -rw-r--r-- | challenge-006/ryan-thompson/README | 1 | ||||
| -rwxr-xr-x | challenge-006/ryan-thompson/perl5/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-006/ryan-thompson/perl5/ch-2.pl | 15 | ||||
| -rw-r--r-- | challenge-006/ryan-thompson/perl6/ch-1.p6 | 13 | ||||
| -rw-r--r-- | challenge-006/ryan-thompson/perl6/ch-2.p6 | 7 |
5 files changed, 67 insertions, 0 deletions
diff --git a/challenge-006/ryan-thompson/README b/challenge-006/ryan-thompson/README new file mode 100644 index 0000000000..53b1e7cfa0 --- /dev/null +++ b/challenge-006/ryan-thompson/README @@ -0,0 +1 @@ +Solutions by Ryan Thompson. diff --git a/challenge-006/ryan-thompson/perl5/ch-1.pl b/challenge-006/ryan-thompson/perl5/ch-1.pl new file mode 100755 index 0000000000..5d0402273d --- /dev/null +++ b/challenge-006/ryan-thompson/perl5/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl +# +# ch-1.pl - Compactify list of numbers +# +# Ryan Thompson <rjt@cpan.org> + +use 5.010; +use warnings; +use strict; +no warnings 'uninitialized'; + +my @list = split /[, ]+/, join(',', @ARGV); # Be flexible. 1,2, 3 4 ,,5 is OK + +my ($last, $start); + +my @compact; +for (@list, undef) { + if ($last and $_ - $last == 1) { + $start //= $last; + } else { + if ($start) { + push @compact, "$start-$last"; + $start = undef; + } else { + push @compact, $last if $last; + } + } + $last = $_; +} + +say join(',', @compact); diff --git a/challenge-006/ryan-thompson/perl5/ch-2.pl b/challenge-006/ryan-thompson/perl5/ch-2.pl new file mode 100644 index 0000000000..4a290e4c31 --- /dev/null +++ b/challenge-006/ryan-thompson/perl5/ch-2.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# +# ch-2.pl - Calculate Ramanujan's constant (๐**(ฯ*sqrt(163))) +# +# Ryan Thompson <rjt@cpan.org> + +use 5.010; +use warnings; +use strict; +use utf8; + +use constant ฯ => 3.14159265359; +use constant ๐ => 2.71828182846; + +say ๐**(ฯ * sqrt(163)); diff --git a/challenge-006/ryan-thompson/perl6/ch-1.p6 b/challenge-006/ryan-thompson/perl6/ch-1.p6 new file mode 100644 index 0000000000..1b4a40f029 --- /dev/null +++ b/challenge-006/ryan-thompson/perl6/ch-1.p6 @@ -0,0 +1,13 @@ +#!/usr/bin/env perl6 + +# ch-1.p6 - Compactify list of numbers +# +# Ryan Thompson <rjt@cpan.org> + +use v6; + +my @list = split /<[, ]>+/, join(',', @*ARGS); # Accept commas or spaces + +my @delta = @list.rotate ยป-ยซ @list; + +@delta.say; diff --git a/challenge-006/ryan-thompson/perl6/ch-2.p6 b/challenge-006/ryan-thompson/perl6/ch-2.p6 new file mode 100644 index 0000000000..5b94ee1125 --- /dev/null +++ b/challenge-006/ryan-thompson/perl6/ch-2.p6 @@ -0,0 +1,7 @@ +#!/usr/bin/env perl6 + +# ch-2.p6 - Calculate Ramanujan's constant ๐**(ฯ * sqrt(163)) +# +# Ryan Thompson <rjt@cpan.org> + +say ๐**( ฯ * 163.sqrt ); |
