diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-05-01 11:31:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-01 11:31:38 +0100 |
| commit | 78abeda61f6c7b41b8c0a8e104fb0ddc08df194c (patch) | |
| tree | a30a58722e05595968b2e6b00f7376fc7270f167 | |
| parent | 2571bf05e210db6660b3c07cefac1eb5dcdae826 (diff) | |
| parent | 26de01e69ab0409eecd7d2b84d9986d82a782439 (diff) | |
| download | perlweeklychallenge-club-78abeda61f6c7b41b8c0a8e104fb0ddc08df194c.tar.gz perlweeklychallenge-club-78abeda61f6c7b41b8c0a8e104fb0ddc08df194c.tar.bz2 perlweeklychallenge-club-78abeda61f6c7b41b8c0a8e104fb0ddc08df194c.zip | |
Merge pull request #107 from gnustavo/mine-006
Gustavo Chaves's perl5 solutions to challenge 006
| -rwxr-xr-x | challenge-006/gustavo-chaves/perl5/ch-1.pl | 24 | ||||
| -rwxr-xr-x | challenge-006/gustavo-chaves/perl5/ch-2.pl | 12 |
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-006/gustavo-chaves/perl5/ch-1.pl b/challenge-006/gustavo-chaves/perl5/ch-1.pl new file mode 100755 index 0000000000..6a50d993ba --- /dev/null +++ b/challenge-006/gustavo-chaves/perl5/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl + +# Create a script which takes a list of numbers from command line and print the +# same in the compact form. For example, if you pass “1,2,3,4,9,10,14,15,16” +# then it should print the compact form like “1-4,9,10,14-16”. + +use strict; +use warnings; + +# The script should be invoked with a single argument which is a comma-separated +# list of integers in ascending order. + +my ($from, @list) = split /,/, shift; +my $to = $from; + +foreach my $n (@list) { + if ($n > $to + 1) { + print $from == $to ? "$to," : "$from-$to,"; + $from = $n; + } + $to = $n; +} + +print $from == $to ? "$to\n" : "$from-$to\n"; diff --git a/challenge-006/gustavo-chaves/perl5/ch-2.pl b/challenge-006/gustavo-chaves/perl5/ch-2.pl new file mode 100755 index 0000000000..e55d1e5919 --- /dev/null +++ b/challenge-006/gustavo-chaves/perl5/ch-2.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl + +# Create a script to calculate Ramanujan’s constant with at least 32 digits of +# precision. Find out more about it here: +# https://en.wikipedia.org/wiki/Heegner_number#Almost_integers_and_Ramanujan's_constant + +use 5.026; +use strict; +use warnings; +use bignum 'PI'; + +say PI()->bmul(sqrt(163))->bexp(32); |
