From 26de01e69ab0409eecd7d2b84d9986d82a782439 Mon Sep 17 00:00:00 2001 From: "Gustavo L. de M. Chaves" Date: Tue, 30 Apr 2019 22:33:28 -0300 Subject: Gustavo Chaves's perl5 solutions to challenge 006 --- challenge-006/gustavo-chaves/perl5/ch-1.pl | 24 ++++++++++++++++++++++++ challenge-006/gustavo-chaves/perl5/ch-2.pl | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100755 challenge-006/gustavo-chaves/perl5/ch-1.pl create mode 100755 challenge-006/gustavo-chaves/perl5/ch-2.pl 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); -- cgit