diff options
| author | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-04-30 22:33:28 -0300 |
|---|---|---|
| committer | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-04-30 22:33:28 -0300 |
| commit | 26de01e69ab0409eecd7d2b84d9986d82a782439 (patch) | |
| tree | 4bf76d0904f33de7099803092b45ebbf88a3241f | |
| parent | 2f5ee8d01e0212d9c8e587014b0df2710e0b0ef1 (diff) | |
| download | perlweeklychallenge-club-26de01e69ab0409eecd7d2b84d9986d82a782439.tar.gz perlweeklychallenge-club-26de01e69ab0409eecd7d2b84d9986d82a782439.tar.bz2 perlweeklychallenge-club-26de01e69ab0409eecd7d2b84d9986d82a782439.zip | |
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); |
