diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2019-05-01 11:31:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-01 11:31:11 +0100 |
| commit | 2571bf05e210db6660b3c07cefac1eb5dcdae826 (patch) | |
| tree | 926263ef1a213b97a9f2aed769ff805dc54f3357 | |
| parent | de15fe19c732b9425edc58c80f172c7d1d5bfd8c (diff) | |
| parent | 0c63db48073745086426393038efc5cb49f28435 (diff) | |
| download | perlweeklychallenge-club-2571bf05e210db6660b3c07cefac1eb5dcdae826.tar.gz perlweeklychallenge-club-2571bf05e210db6660b3c07cefac1eb5dcdae826.tar.bz2 perlweeklychallenge-club-2571bf05e210db6660b3c07cefac1eb5dcdae826.zip | |
Merge pull request #108 from softmoth/softmoth
Add tim-smith/perl6/*
| -rwxr-xr-x | challenge-006/tim-smith/perl6/ch-1.p6 | 21 | ||||
| -rwxr-xr-x | challenge-006/tim-smith/perl6/ch-2.p6 | 12 |
2 files changed, 33 insertions, 0 deletions
diff --git a/challenge-006/tim-smith/perl6/ch-1.p6 b/challenge-006/tim-smith/perl6/ch-1.p6 new file mode 100755 index 0000000000..506c8802e9 --- /dev/null +++ b/challenge-006/tim-smith/perl6/ch-1.p6 @@ -0,0 +1,21 @@ +#! /usr/bin/env perl6 + +# Comb all args for numbers, then flatten them into a single list of +# increasing integers +my @vals = @*ARGSĀ».comb(/\d+/).Seq.flatĀ».Int.sort.unique + or die "Usage: {$?FILE.IO.basename} 1 2,3 4/5/6 '7 8 9'"; + +my @groups; + +for @vals -> $n { + # Add a new group unless $n belongs in the current group + unless @groups and @groups.tail[1] == $n - 1 { + @groups.push: [$n, Nil]; + } + + # Update the endpoint of the current group + @groups.tail[1] = $n; +} + +# Display the groups +put @groups.map(*.unique.join('-')).join(','); diff --git a/challenge-006/tim-smith/perl6/ch-2.p6 b/challenge-006/tim-smith/perl6/ch-2.p6 new file mode 100755 index 0000000000..73a74698c2 --- /dev/null +++ b/challenge-006/tim-smith/perl6/ch-2.p6 @@ -0,0 +1,12 @@ +#! /usr/bin/env perl6 + +# https://en.wikipedia.org/wiki/Heegner_number#Almost_integers_and_Ramanujan's_constant + +# Ramanujan's constant is _almost_ this integer ... +my $r = 640_320 ** 3 + 744; + +# But is off by an error which is defined in terms of the constant itself, +# so this approximation is close enough for at least 32 significant digits. +$r += FatRat.new: -196_844, $r; + +put substr($r, 0, 33); |
