aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Russell <ac.russell@live.com>2019-05-03 00:35:19 -0400
committerAdam Russell <ac.russell@live.com>2019-05-03 00:35:19 -0400
commit17e3a37d3fd6bcc4219336e7bea9cf5ba8cf1be0 (patch)
treec4a882062cc0804472a935b3e801d71efcea3f19
parentf672cd2a5494692f01e25491da63c64f2c859a71 (diff)
parent32ab749b5a997c7791867f6e7e1c4a5f6fdab8d1 (diff)
downloadperlweeklychallenge-club-17e3a37d3fd6bcc4219336e7bea9cf5ba8cf1be0.tar.gz
perlweeklychallenge-club-17e3a37d3fd6bcc4219336e7bea9cf5ba8cf1be0.tar.bz2
perlweeklychallenge-club-17e3a37d3fd6bcc4219336e7bea9cf5ba8cf1be0.zip
Merge remote-tracking branch 'upstream/master'
-rw-r--r--challenge-006/alicia-bielsa/perl5/ch-1.pl85
-rw-r--r--challenge-006/andrezgz/perl5/ch-1.pl34
-rw-r--r--challenge-006/andrezgz/perl5/ch-2.pl13
-rw-r--r--challenge-006/athanasius/perl5/ch-1.pl46
-rw-r--r--challenge-006/athanasius/perl5/ch-2.pl23
-rw-r--r--challenge-006/e-choroba/blog.txt1
-rw-r--r--challenge-006/e-choroba/perl5/ch-1.pl17
-rw-r--r--challenge-006/e-choroba/perl5/ch-2.pl14
-rwxr-xr-xchallenge-006/gustavo-chaves/perl5/ch-1.pl24
-rwxr-xr-xchallenge-006/gustavo-chaves/perl5/ch-2.pl12
-rw-r--r--challenge-006/laurent-rosenfeld/blog.txt1
-rw-r--r--challenge-006/laurent-rosenfeld/perl5/ch-1.pl15
-rw-r--r--challenge-006/laurent-rosenfeld/perl5/ch-1a.pl16
-rw-r--r--challenge-006/laurent-rosenfeld/perl5/ch-1b.pl27
-rw-r--r--challenge-006/laurent-rosenfeld/perl5/ch-1c.pl23
-rw-r--r--challenge-006/laurent-rosenfeld/perl5/ch-1d.pl24
-rw-r--r--challenge-006/laurent-rosenfeld/perl6/ch-1.p620
-rw-r--r--challenge-006/laurent-rosenfeld/perl6/ch-1a.p615
-rw-r--r--challenge-006/maxim-kolodyazhny/perl5/ch-1.pl18
-rw-r--r--challenge-006/maxim-kolodyazhny/perl5/ch-2.pl10
-rwxr-xr-xchallenge-006/simon-proctor/perl6/ch-1.p657
-rwxr-xr-xchallenge-006/tim-smith/perl6/ch-1.p621
-rwxr-xr-xchallenge-006/tim-smith/perl6/ch-2.p612
-rw-r--r--stats/pwc-current.json225
-rw-r--r--stats/pwc-language-breakdown.json96
-rw-r--r--stats/pwc-leaders.json914
-rw-r--r--stats/pwc-summary-1-30.json116
-rw-r--r--stats/pwc-summary-31-60.json26
-rw-r--r--stats/pwc-summary-61-90.json40
-rw-r--r--stats/pwc-summary.json218
30 files changed, 1415 insertions, 748 deletions
diff --git a/challenge-006/alicia-bielsa/perl5/ch-1.pl b/challenge-006/alicia-bielsa/perl5/ch-1.pl
new file mode 100644
index 0000000000..9570089b3a
--- /dev/null
+++ b/challenge-006/alicia-bielsa/perl5/ch-1.pl
@@ -0,0 +1,85 @@
+#Challenge #1 week 6
+#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;
+use Data::Dumper;
+
+my $askForInput = 1;
+my $errorMessage = '';
+my $compactedNumbers = '';
+my $rangeDivider = '-';
+my $numberDivider = ',';
+
+while ($askForInput){
+
+ if ($errorMessage ){
+ print "ERROR: $errorMessage\n";
+ }
+ my $input = getInput();
+ print "Input: '$input'\n";
+ if ($input =~ /[\d+]/){
+ $errorMessage = '';
+ $compactedNumbers = compactNumbers($input);
+ print "Compact form: $compactedNumbers\n";
+ } else {
+ $errorMessage = "Only digits separated by commas are valid input\n";
+ }
+ if ($input =~ /^q|quit$/i){
+ print "Bye bye\n";
+ $askForInput = 0;
+ }
+}
+
+ sub getInput {
+ print "Enter numbers separated by commas, example: 1,2,3\nEnter quit(q) to exit\n";
+ my $input = <STDIN>;
+ chomp($input);
+ $input =~ s%\s+%%g; #eliminate spaces
+ $input =~ s%^,+%%g; #eliminate commas at begining
+ $input =~ s%,+$%%g; #eliminate commas at end
+ $input =~ s%,+%,%g; #eliminate duplicated commas
+ return $input;
+ }
+
+ sub compactNumbers {
+ my $numbers = shift;
+ my $compactNumbers = '';
+ my @aNumbers = split ( ',' , $numbers );
+
+ #we eliminate duplicated numbers by passing to hash and back to array
+ my %hNumbers = ();
+ $hNumbers{$_}++ for (@aNumbers);
+ @aNumbers = keys %hNumbers;
+
+ # we sort the numbers
+ @aNumbers = sort { $a <=> $b } @aNumbers;
+
+ my $rangeCount = 0;
+ my $divider = '';
+
+ for my $i (0 .. $#aNumbers) {
+ unless ( $i == 0 ){
+ $divider = $numberDivider;
+ }
+ if ( ( $i != $#aNumbers ) && ( $aNumbers[$i] +1 == $aNumbers[$i+1] ) ){
+ $rangeCount++;
+ if ( $rangeCount > 1 ){
+ next;
+ }
+ } else {
+ if ( $rangeCount > 1 ){
+ $divider = $rangeDivider;
+ }
+ $rangeCount = 0;
+ }
+ $compactNumbers .= $divider.$aNumbers[$i];
+ }
+
+ return $compactNumbers;
+ }
+
+
diff --git a/challenge-006/andrezgz/perl5/ch-1.pl b/challenge-006/andrezgz/perl5/ch-1.pl
new file mode 100644
index 0000000000..b0843cca96
--- /dev/null
+++ b/challenge-006/andrezgz/perl5/ch-1.pl
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-006/
+# Challenge #1
+# 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;
+
+
+die "Usage: ch-1.pl <numbers_list>" unless ($ARGV[0]);
+
+# Numbers are sorted in ascending order just in case
+my @numbers = sort {$a <=> $b} split ',', $ARGV[0];
+
+my ($first, $last) = (shift @numbers) x 2;
+
+foreach my $n (@numbers){
+ if ($n - $last > 1) {
+ print compact_term($first, $last).',';
+ $first = $n;
+ }
+ $last = $n;
+}
+
+print compact_term($first, $last).$/;
+
+# Returns a term for the compact form: a single number, two numbers (m,n) or a range (m-n)
+sub compact_term {
+ my ($first, $last) = @_;
+ my $separator = ($last - $first == 1) ? ',' : '-';
+ return ($last == $first) ? $first : $first.$separator.$last;
+}
diff --git a/challenge-006/andrezgz/perl5/ch-2.pl b/challenge-006/andrezgz/perl5/ch-2.pl
new file mode 100644
index 0000000000..ffe30f9767
--- /dev/null
+++ b/challenge-006/andrezgz/perl5/ch-2.pl
@@ -0,0 +1,13 @@
+#!/usr/bin/perl
+
+# https://perlweeklychallenge.org/blog/perl-weekly-challenge-006/
+# Challenge #2
+# 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 strict;
+use warnings;
+
+use Math::BigFloat qw/bpi/;
+
+print Math::BigFloat->new(163)->bsqrt->bmul(bpi)->bexp(32);
diff --git a/challenge-006/athanasius/perl5/ch-1.pl b/challenge-006/athanasius/perl5/ch-1.pl
new file mode 100644
index 0000000000..e916b409dd
--- /dev/null
+++ b/challenge-006/athanasius/perl5/ch-1.pl
@@ -0,0 +1,46 @@
+use strict;
+use warnings;
+
+if (@ARGV != 1 || $ARGV[0] =~ /[^\d,+-]/)
+{
+ print "\nUsage: perl $0 < comma-separated integer list (no spaces) >\n";
+ exit 0;
+}
+
+my @numbers = split /,/, $ARGV[0];
+my $last = shift @numbers;
+my @runs = ( [ $last ] );
+
+while (my $n = shift @numbers)
+{
+ if ($n == $last + 1)
+ {
+ push $runs[-1]->@*, $n;
+ }
+ else
+ {
+ push @runs, [ $n ];
+ }
+
+ $last = $n;
+}
+
+my @ranges;
+
+for my $run (@runs)
+{
+ if (scalar @$run > 2)
+ {
+ push @ranges, $run->[0] . '-' . $run->[-1];
+ }
+ else
+ {
+ push @ranges, join(',', @$run);
+ }
+}
+
+print "\n", join(',', @ranges), "\n";
+
+__END__
+
+0:37 >perl ch-1.pl 1,2,3,4,9,10,14,15,16,18
diff --git a/challenge-006/athanasius/perl5/ch-2.pl b/challenge-006/athanasius/perl5/ch-2.pl
new file mode 100644
index 0000000000..4445fb287e
--- /dev/null
+++ b/challenge-006/athanasius/perl5/ch-2.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use Const::Fast;
+use Math::BigFloat;
+
+const my $INT_DIGITS => 18;
+const my $HEEGNER => 163;
+const my $PRECISION => 33;
+const my $ACCURACY => $INT_DIGITS + $PRECISION + 3;
+
+Math::BigFloat->accuracy($ACCURACY);
+
+my $squareroot = Math::BigFloat->new($HEEGNER)->bsqrt(); # sqrt(163)
+my $ramanujan = Math::BigFloat->bpi(); # pi
+$ramanujan->bmul($squareroot); # pi * sqrt(163)
+$ramanujan->bexp(); # e^(pi * sqrt(163))
+$ramanujan->bfround(-$PRECISION); # to 33 decimal places
+
+print "\n$ramanujan\n";
+
+__END__
+
+0:37 >perl ch-2.pl
diff --git a/challenge-006/e-choroba/blog.txt b/challenge-006/e-choroba/blog.txt
new file mode 100644
index 0000000000..808a14970e
--- /dev/null
+++ b/challenge-006/e-choroba/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/e_choroba/2019/04/perl-weekly-challenge-006-ranges-and-ramanujans-constant.html
diff --git a/challenge-006/e-choroba/perl5/ch-1.pl b/challenge-006/e-choroba/perl5/ch-1.pl
new file mode 100644
index 0000000000..de88538c0e
--- /dev/null
+++ b/challenge-006/e-choroba/perl5/ch-1.pl
@@ -0,0 +1,17 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+
+is compact('1,2,3,4,9,10,14,15,16'), '1-4,9,10,14-16';
+
+use String::Util::Range qw{ convert_sequence_to_range };
+sub compact {
+ my ($seq_string) = @_;
+ join ',', @{ convert_sequence_to_range(
+ array => [split /,/, $seq_string],
+ threshold => 3,
+ separator => '-')
+ };
+}
diff --git a/challenge-006/e-choroba/perl5/ch-2.pl b/challenge-006/e-choroba/perl5/ch-2.pl
new file mode 100644
index 0000000000..f0c30638ed
--- /dev/null
+++ b/challenge-006/e-choroba/perl5/ch-2.pl
@@ -0,0 +1,14 @@
+#! /usr/bin/perl
+use warnings;
+use strict;
+use feature qw{ say };
+
+use Math::BigFloat;
+
+use constant ACCURACY => 64;
+
+my $r = ('Math::BigFloat'->bpi(ACCURACY)
+ * 'Math::BigFloat'->new(163)->bsqrt(ACCURACY)
+ )->bexp;
+$r->precision(-32);
+say $r;
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);
diff --git a/challenge-006/laurent-rosenfeld/blog.txt b/challenge-006/laurent-rosenfeld/blog.txt
new file mode 100644
index 0000000000..54d90dc3a7
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/blog.txt
@@ -0,0 +1 @@
+http://blogs.perl.org/users/laurent_r/2019/05/perl-weekly-challenge-6-compact-number-ranges.html
diff --git a/challenge-006/laurent-rosenfeld/perl5/ch-1.pl b/challenge-006/laurent-rosenfeld/perl5/ch-1.pl
new file mode 100644
index 0000000000..43773de58d
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl5/ch-1.pl
@@ -0,0 +1,15 @@
+use strict;
+use warnings;
+use feature 'say';
+
+my @input = @ARGV > 0 ? @ARGV : (1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9);
+my $prev = my $start = shift @input;
+for my $num (@input) {
+ if ( $prev == $num - 1 ) {
+ $prev = $num;
+ } else {
+ print $prev == $start ? "$prev," : "$start-$prev,";
+ $start = $prev = $num;
+ }
+}
+say $prev == $start ? $prev : "$start-$prev";
diff --git a/challenge-006/laurent-rosenfeld/perl5/ch-1a.pl b/challenge-006/laurent-rosenfeld/perl5/ch-1a.pl
new file mode 100644
index 0000000000..cd1d9d66f1
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl5/ch-1a.pl
@@ -0,0 +1,16 @@
+use strict;
+use warnings;
+use feature 'say';
+
+my @input = @ARGV > 0 ? @ARGV : (1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9);
+my $prev = my $start = shift @input;
+for my $num (sort { $a <=> $b } @input) {
+ next if $num == $prev;
+ if ( $prev == $num - 1 ) {
+ $prev = $num;
+ } else {
+ print $prev == $start ? "$prev," : "$start-$prev,";
+ $start = $prev = $num;
+ }
+}
+say $prev == $start ? $prev : "$start-$prev";
diff --git a/challenge-006/laurent-rosenfeld/perl5/ch-1b.pl b/challenge-006/laurent-rosenfeld/perl5/ch-1b.pl
new file mode 100644
index 0000000000..deb1b6cd3f
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl5/ch-1b.pl
@@ -0,0 +1,27 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub compare {
+ my ($prev, $start) = @_;
+ if ($prev > $start + 1) {
+ return "$start-$prev";
+ } elsif ($prev > $start) {
+ return "$start,$prev";
+ } else {
+ return "$prev";
+ }
+}
+
+my @input = @ARGV > 0 ? @ARGV : (1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9);
+my $prev_val = my $start_val = shift @input;
+my $output = "";
+for my $num (@input) {
+ if ($num != $prev_val + 1) {
+ $output .= compare ($prev_val, $start_val) . ",";
+ $start_val = $num;
+ }
+ $prev_val = $num;
+}
+$output .= compare ($prev_val, $start_val);
+say $output;
diff --git a/challenge-006/laurent-rosenfeld/perl5/ch-1c.pl b/challenge-006/laurent-rosenfeld/perl5/ch-1c.pl
new file mode 100644
index 0000000000..9de0e3f3f0
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl5/ch-1c.pl
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use feature 'say';
+
+sub compare {
+ my ($prev, $start) = @_;
+ return $prev > $start + 1 ? "$start-$prev"
+ : $prev > $start ? "$start,$prev"
+ : "$prev";
+}
+
+my @input = @ARGV > 0 ? @ARGV : (1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9);
+my $prev_val = my $start_val = shift @input;
+my $output = "";
+for my $num (@input) {
+ if ($num != $prev_val + 1) {
+ $output .= compare ($prev_val, $start_val) . ",";
+ $start_val = $num;
+ }
+ $prev_val = $num;
+}
+$output .= compare ($prev_val, $start_val);
+say $output;
diff --git a/challenge-006/laurent-rosenfeld/perl5/ch-1d.pl b/challenge-006/laurent-rosenfeld/perl5/ch-1d.pl
new file mode 100644
index 0000000000..65368e5871
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl5/ch-1d.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+use feature 'say';
+
+my @input = @ARGV > 0 ? @ARGV : (1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9);
+
+sub process_input {
+ my ($range, $input, $output) = @_;
+ my $curr_val = shift @$input;
+ if ($curr_val == $range->[1] + 1) {
+ $range->[1] = $curr_val;
+ } else {
+ my $sep = $range->[1] > $range->[0] + 1 ? "-" : ",";
+ $output .= (join $sep, @$range) . ",";
+ $range = [$curr_val, $curr_val];
+ }
+ return $output if @$input == 0;
+ process_input ($range, $input, $output);
+}
+
+my $first = shift @input;
+my $output = process_input([($first) x 2], \@input, "");
+chop $output;
+say $output;
diff --git a/challenge-006/laurent-rosenfeld/perl6/ch-1.p6 b/challenge-006/laurent-rosenfeld/perl6/ch-1.p6
new file mode 100644
index 0000000000..a57a0af39a
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl6/ch-1.p6
@@ -0,0 +1,20 @@
+use v6;
+sub compare (Int $prev, Int $start) {
+ return $prev > $start + 1 ?? "$start-$prev"
+ !! $prev > $start ?? "$start,$prev"
+ !! "$prev";
+}
+
+my @input = @*ARGS.elems > 0 ?? @*ARGS !! 1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9;
+my $prev_val = my $start_val = shift @input;
+
+my $output = "";
+for @input -> $num {
+ if ($num != $prev_val + 1) {
+ $output ~= compare($prev_val, $start_val) ~ ",";
+ $start_val = $num;
+ }
+ $prev_val = $num;
+}
+$output ~= compare $prev_val, $start_val;
+say $output;
diff --git a/challenge-006/laurent-rosenfeld/perl6/ch-1a.p6 b/challenge-006/laurent-rosenfeld/perl6/ch-1a.p6
new file mode 100644
index 0000000000..98fa613908
--- /dev/null
+++ b/challenge-006/laurent-rosenfeld/perl6/ch-1a.p6
@@ -0,0 +1,15 @@
+use v6;
+my @input = @*ARGS.elems > 0 ?? @*ARGS !! 1,2,3,4,9,10,14,15,16,3,4,5,6,4,5,6,7,9,9;
+my $prev = my $start = shift @input;
+my @result = gather {
+ for @input -> $num {
+ if $num != $prev + 1 {
+ take $prev > $start + 1 ?? "$start-$prev"
+ !! $prev > $start ?? "$start,$prev"
+ !! "$prev";
+ $start = $num;
+ }
+ $prev = $num;
+ }
+}
+say @result.append($prev).join(",");
diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl
new file mode 100644
index 0000000000..4ccfcc64a3
--- /dev/null
+++ b/challenge-006/maxim-kolodyazhny/perl5/ch-1.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/env perl -p
+
+# echo 1,2,3,4,42,43,45 | ch-1.pl
+
+use 5.028.1;
+use List::Util qw(sum);
+
+s{
+ ( \b \d+ )
+ ( ,? \d+ , )+
+ ( \d+ \b )
+ (??{
+ # this block is treated as a pattern
+ # != will return '' (always match) or 1 (fail because of previous \b)
+ ($3-$1+1)*($1+$3)/2 != sum split ',', $&;
+ })
+}
+{$1-$3}xg;
diff --git a/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl
new file mode 100644
index 0000000000..23e6977981
--- /dev/null
+++ b/challenge-006/maxim-kolodyazhny/perl5/ch-2.pl
@@ -0,0 +1,10 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use v5.028.1;
+
+use bigrat qw(bexp PI);
+
+say bexp(PI*sqrt(163),80);
diff --git a/challenge-006/simon-proctor/perl6/ch-1.p6 b/challenge-006/simon-proctor/perl6/ch-1.p6
new file mode 100755
index 0000000000..6d3c0f0715
--- /dev/null
+++ b/challenge-006/simon-proctor/perl6/ch-1.p6
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+class GrowableRange {
+ has Int $.min;
+ has Int $.max;
+
+ submethod BUILD( Int :$!min, Int :$!max ) {}
+
+ method next() { $!max + 1 }
+
+ method grow() { $!max++; return self }
+
+ method gist() { $!min == $!max ??
+ $!min.Str !! $!max == $!min+1 ??
+ "{$!min},{$!max}"
+ !! "{$!min}-{$!max}" }
+
+ method Str() { self.gist }
+}
+
+sub USAGE { say $*USAGE }
+
+#| Display Help file
+multi sub MAIN ( Bool :h($help) where *.so ) { USAGE(); }
+
+#| Get the shortend list of a CSV string
+multi sub MAIN (
+ Str $number-string where * ~~ /^ \d+ [ ',' \d+ ]* $/ #= Comma seperated list of numbers
+) {
+ my Int @in = [$_.Int for $number-string.split(",")].sort( * <=> * );
+ say process-list( @in );
+}
+
+#| Get the shorted list of a space seperated list of number
+multi sub MAIN (
+ *@numbers where { all($_) ~~ IntStr } #= List of integers
+) {
+ my Int @in = [$_.Int for @numbers].sort( * <=> * );
+ say process-list( @in );
+}
+
+sub process-list( Int @numbers ) {
+ my $current;
+ my @out;
+
+ for @numbers -> $number {
+ if @out.elems == 0 || @out[*-1].next != $number {
+ @out.push( GrowableRange.new( min => $number, max => $number ) );
+ } else {
+ @out[*-1].grow;
+ }
+ }
+
+ return @out.join(",");
+}
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);
diff --git a/stats/pwc-current.json b/stats/pwc-current.json
index f3922557ad..022df4c9c2 100644
--- a/stats/pwc-current.json
+++ b/stats/pwc-current.json
@@ -1,50 +1,63 @@
{
- "tooltip" : {
- "followPointer" : 1,
- "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>",
- "pointerFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>"
- },
- "yAxis" : {
- "title" : {
- "text" : "Total Solutions"
- }
- },
- "chart" : {
- "type" : "column"
- },
- "series" : [
- {
- "name" : "Champions",
- "colorByPoint" : 1,
- "data" : [
- {
- "drilldown" : "Joelle Maslak",
- "y" : 4,
- "name" : "Joelle Maslak"
- }
- ]
- }
- ],
- "plotOptions" : {
- "series" : {
- "dataLabels" : {
- "format" : "{point.y}",
- "enabled" : 1
- },
- "borderWidth" : 0
- }
- },
"subtitle" : {
- "text" : "[Champions: 1] Last updated at 2019-04-29 09:24:04 GMT"
+ "text" : "[Champions: 10] Last updated at 2019-05-02 18:53:17 GMT"
},
- "legend" : {
- "enabled" : 0
+ "xAxis" : {
+ "type" : "category"
},
"drilldown" : {
"series" : [
{
- "id" : "Joelle Maslak",
- "name" : "Joelle Maslak",
+ "id" : "Alicia Bielsa",
+ "name" : "Alicia Bielsa",
+ "data" : [
+ [
+ "Perl 5",
+ 1
+ ]
+ ]
+ },
+ {
+ "name" : "Andrezgz",
+ "id" : "Andrezgz",
+ "data" : [
+ [
+ "Perl 5",
+ 2
+ ]
+ ]
+ },
+ {
+ "data" : [
+ [
+ "Perl 5",
+ 2
+ ]
+ ],
+ "name" : "Athanasius",
+ "id" : "Athanasius"
+ },
+ {
+ "data" : [
+ [
+ "Perl 5",
+ 2
+ ]
+ ],
+ "id" : "E. Choroba",
+ "name" : "E. Choroba"
+ },
+ {
+ "data" : [
+ [
+ "Perl 5",
+ 2
+ ]
+ ],
+ "id" : "Gustavo Chaves",
+ "name" : "Gustavo Chaves"
+ },
+ {
"data" : [
[
"Perl 5",
@@ -54,14 +67,140 @@
"Perl 6",
2
]
- ]
+ ],
+ "id" : "Joelle Maslak",
+ "name" : "Joelle Maslak"
+ },
+ {
+ "data" : [
+ [
+ "Perl 5",
+ 1
+ ],
+ [
+ "Perl 6",
+ 1
+ ]
+ ],
+ "id" : "Laurent Rosenfeld",
+ "name" : "Laurent Rosenfeld"
+ },
+ {
+ "data" : [
+ [
+ "Perl 5",
+ 2
+ ]
+ ],
+ "id" : "Maxim Kolodyazhny",
+ "name" : "Maxim Kolodyazhny"
+ },
+ {
+ "data" : [
+ [
+ "Perl 6",
+ 1
+ ]
+ ],
+ "name" : "Simon Proctor",
+ "id" : "Simon Proctor"
+ },
+ {
+ "data" : [
+ [
+ "Perl 6",
+ 2
+ ]
+ ],
+ "id" : "Tim Smith",
+ "name" : "Tim Smith"
}
]
},
+ "legend" : {
+ "enabled" : 0
+ },
+ "chart" : {
+ "type" : "column"
+ },
+ "series" : [
+ {
+ "data" : [
+ {
+ "drilldown" : "Alicia Bielsa",
+ "name" : "Alicia Bielsa",
+ "y" : 1
+ },
+ {
+ "drilldown" : "Andrezgz",
+ "name" : "Andrezgz",
+ "y" : 2
+ },
+ {
+ "y" : 2,
+ "name" : "Athanasius",
+ "drilldown" : "Athanasius"
+ },
+ {
+ "y" : 2,
+ "name" : "E. Choroba",
+ "drilldown" : "E. Choroba"
+ },
+ {
+ "drilldown" : "Gustavo Chaves",
+ "name" : "Gustavo Chaves",
+ "y" : 2
+ },
+ {
+ "y" : 4,
+ "name" : "Joelle Maslak",