aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-006/tim-smith/perl6/ch-1.p621
-rwxr-xr-xchallenge-006/tim-smith/perl6/ch-2.p612
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);