diff options
| -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); |
