From 05bf450ccda1b6cfb0e796cd0c3ebef7cfc7349e Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Sun, 11 Oct 2020 23:40:37 -0600 Subject: initial --- challenge-082/mark-anderson/raku/ch-1.p6 | 12 ++++++++++++ challenge-082/mark-anderson/raku/ch-2.p6 | 21 +++++++++++++++++++++ challenge-082/mark-anderson/raku/terms.json | 1 + 3 files changed, 34 insertions(+) create mode 100644 challenge-082/mark-anderson/raku/ch-1.p6 create mode 100644 challenge-082/mark-anderson/raku/ch-2.p6 create mode 100644 challenge-082/mark-anderson/raku/terms.json diff --git a/challenge-082/mark-anderson/raku/ch-1.p6 b/challenge-082/mark-anderson/raku/ch-1.p6 new file mode 100644 index 0000000000..42e1fe2b36 --- /dev/null +++ b/challenge-082/mark-anderson/raku/ch-1.p6 @@ -0,0 +1,12 @@ +unit sub MAIN(UInt $m, UInt $n); + +say common-factors($m, $n); + +sub common-factors($m, $n) { + + sub factor($i) { + (1..($i div 2)).grep($i %% *); + } + + (factor($m) (&) factor($n)).keys.sort.join(", ").List; +} diff --git a/challenge-082/mark-anderson/raku/ch-2.p6 b/challenge-082/mark-anderson/raku/ch-2.p6 new file mode 100644 index 0000000000..1d67d02a79 --- /dev/null +++ b/challenge-082/mark-anderson/raku/ch-2.p6 @@ -0,0 +1,21 @@ +use JSON::Fast; + +subset Tiny-Str of Str where .chars < 10; + +#| A.chars < 10, B.chars < 10, C.chars == A.chars + B.chars +unit sub MAIN(Tiny-Str $A, Tiny-Str $B, $C where .chars == $A.chars + $B.chars); + +my @terms := |from-json "terms.json".IO.slurp; + +say interleaved($A, $B, $C); + +sub interleaved($S1, $S2, $C) { + for ($S1, $S2), ($S2, $S1) -> ($A, $B) { + for @terms[$A.chars].Array X @terms[$B.chars].Array -> (@A, @B) { + return 1 if roundrobin($A.comb.rotor(@A), $B.comb.rotor(@B)) + .flat.join eq $C; + } + } + + return 0; +} diff --git a/challenge-082/mark-anderson/raku/terms.json b/challenge-082/mark-anderson/raku/terms.json new file mode 100644 index 0000000000..ca62128af6 --- /dev/null +++ b/challenge-082/mark-anderson/raku/terms.json @@ -0,0 +1 @@ +[[[0]],[[1]],[[1,1],[2]],[[1,1,1],[3],[1,2],[2,1]],[[1,1,1,1],[2,2],[4],[1,3],[3,1],[1,1,2],[1,2,1],[2,1,1]],[[1,1,1,1,1],[5],[1,2,2],[2,1,2],[2,2,1],[1,4],[4,1],[1,1,3],[1,3,1],[3,1,1],[1,1,1,2],[1,1,2,1],[1,2,1,1],[2,1,1,1],[2,3],[3,2]],[[1,1,1,1,1,1],[2,2,2],[3,3],[6],[1,5],[5,1],[1,1,2,2],[1,2,1,2],[1,2,2,1],[2,1,1,2],[2,1,2,1],[2,2,1,1],[1,1,4],[1,4,1],[4,1,1],[1,1,1,3],[1,1,3,1],[1,3,1,1],[3,1,1,1],[1,1,1,1,2],[1,1,1,2,1],[1,1,2,1,1],[1,2,1,1,1],[2,1,1,1,1],[2,4],[4,2],[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]],[[1,1,1,1,1,1,1],[7],[1,2,2,2],[2,1,2,2],[2,2,1,2],[2,2,2,1],[1,3,3],[3,1,3],[3,3,1],[1,6],[6,1],[1,1,5],[1,5,1],[5,1,1],[1,1,1,2,2],[1,1,2,1,2],[1,1,2,2,1],[1,2,1,1,2],[1,2,1,2,1],[1,2,2,1,1],[2,1,1,1,2],[2,1,1,2,1],[2,1,2,1,1],[2,2,1,1,1],[1,1,1,4],[1,1,4,1],[1,4,1,1],[4,1,1,1],[1,1,1,1,3],[1,1,1,3,1],[1,1,3,1,1],[1,3,1,1,1],[3,1,1,1,1],[1,1,1,1,1,2],[1,1,1,1,2,1],[1,1,1,2,1,1],[1,1,2,1,1,1],[1,2,1,1,1,1],[2,1,1,1,1,1],[2,5],[5,2],[2,2,3],[2,3,2],[3,2,2],[3,4],[4,3],[1,2,4],[1,4,2],[2,1,4],[2,4,1],[4,1,2],[4,2,1],[1,1,2,3],[1,1,3,2],[1,2,1,3],[1,2,3,1],[1,3,1,2],[1,3,2,1],[2,1,1,3],[2,1,3,1],[2,3,1,1],[3,1,1,2],[3,1,2,1],[3,2,1,1]],[[1,1,1,1,1,1,1,1],[2,2,2,2],[4,4],[8],[1,7],[7,1],[1,1,2,2,2],[1,2,1,2,2],[1,2,2,1,2],[1,2,2,2,1],[2,1,1,2,2],[2,1,2,1,2],[2,1,2,2,1],[2,2,1,1,2],[2,2,1,2,1],[2,2,2,1,1],[1,1,3,3],[1,3,1,3],[1,3,3,1],[3,1,1,3],[3,1,3,1],[3,3,1,1],[1,1,6],[1,6,1],[6,1,1],[1,1,1,5],[1,1,5,1],[1,5,1,1],[5,1,1,1],[1,1,1,1,2,2],[1,1,1,2,1,2],[1,1,1,2,2,1],[1,1,2,1,1,2],[1,1,2,1,2,1],[1,1,2,2,1,1],[1,2,1,1,1,2],[1,2,1,1,2,1],[1,2,1,2,1,1],[1,2,2,1,1,1],[2,1,1,1,1,2],[2,1,1,1,2,1],[2,1,1,2,1,1],[2,1,2,1,1,1],[2,2,1,1,1,1],[1,1,1,1,4],[1,1,1,4,1],[1,1,4,1,1],[1,4,1,1,1],[4,1,1,1,1],[1,1,1,1,1,3],[1,1,1,1,3,1],[1,1,1,3,1,1],[1,1,3,1,1,1],[1,3,1,1,1,1],[3,1,1,1,1,1],[1,1,1,1,1,1,2],[1,1,1,1,1,2,1],[1,1,1,1,2,1,1],[1,1,1,2,1,1,1],[1,1,2,1,1,1,1],[1,2,1,1,1,1,1],[2,1,1,1,1,1,1],[2,3,3],[3,2,3],[3,3,2],[2,6],[6,2],[2,2,4],[2,4,2],[4,2,2],[3,5],[5,3],[1,2,5],[1,5,2],[2,1,5],[2,5,1],[5,1,2],[5,2,1],[1,2,2,3],[1,2,3,2],[1,3,2,2],[2,1,2,3],[2,1,3,2],[2,2,1,3],[2,2,3,1],[2,3,1,2],[2,3,2,1],[3,1,2,2],[3,2,1,2],[3,2,2,1],[1,3,4],[1,4,3],[3,1,4],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],[3,1,1,1,2,1],[3,1,1,2,1,1],[3,1,2,1,1,1],[3,2,1,1,1,1],[2,3,4],[2,4,3],[3,2,4],[3,4,2],[4,2,3],[4,3,2]]] -- cgit From a7585cfb59dd2ffc100cd065858e6d349d60c19f Mon Sep 17 00:00:00 2001 From: Andinus Date: Mon, 12 Oct 2020 14:50:46 +0530 Subject: Add challenge-082's ch-1 solution in Perl --- challenge-082/andinus/README | 126 ++++--------------------------------- challenge-082/andinus/blog-1.txt | 1 + challenge-082/andinus/perl/ch-1.pl | 33 ++++++++++ 3 files changed, 46 insertions(+), 114 deletions(-) create mode 100644 challenge-082/andinus/blog-1.txt create mode 100755 challenge-082/andinus/perl/ch-1.pl diff --git a/challenge-082/andinus/README b/challenge-082/andinus/README index 13354ca364..2ad8a0f3af 100644 --- a/challenge-082/andinus/README +++ b/challenge-082/andinus/README @@ -1,5 +1,5 @@ ━━━━━━━━━━━━━━━ - CHALLENGE 081 + CHALLENGE 082 Andinus ━━━━━━━━━━━━━━━ @@ -8,25 +8,19 @@ Table of Contents ───────────────── -1. Task 1 - Common Base String +1. Task 1 - Common Factors .. 1. Perl -2. Task 2 - Frequency Sort -.. 1. Perl - -1 Task 1 - Common Base String -═════════════════════════════ - You are given 2 strings, `$A' and `$B'. +1 Task 1 - Common Factors +═════════════════════════ - Write a script to find out common base strings in `$A' and `$B'. + You are given 2 positive numbers $M and $N. - A substring of a string $S is called base string if - repeated concatenation of the substring results in the - string. + Write a script to list all common factors of the given numbers. 1.1 Perl @@ -34,42 +28,16 @@ Table of Contents • Program: - We will break `$A' & check if any subset of `$A' join to make `$B'. To - speed up the process we only break `$A' by common divisors of both - `$A' & `$B'. - - I assume that the length of `$B' is greater than `$A' in later parts - so we make sure that it's true. + We loop over all the numbers from `1 ... $M' to get their factors & + then just compare it with factors of `$N'. I took this code from + Challenge 081's ch-1.pl. ┌──── │ my $A = shift @ARGV; │ my $B = shift @ARGV; │ - │ # We assume length($B) is greater than length($A). - │ unless (length($B) > length($A)) { - │ my $tmp = $A; - │ $A = $B; - │ $B = $tmp; - │ } - └──── - - If the strings have different sets of characters then common base - string cannot exists so we exit early. - ┌──── - │ # Check if common base string is even possible. - │ my (%chars_in_A, %chars_in_B); - │ $chars_in_A{$_} = 1 foreach split //, $A; - │ $chars_in_B{$_} = 1 foreach split //, $B; - │ foreach my $char (sort keys %chars_in_A) { - │ last if exists $chars_in_B{$char} ; - │ print "No common base string.\n" and exit 0 - │ } - └──── - - Get all the common divisors of `$A' & `$B'. - ┌──── │ # Get all common divisors. - │ my %divisors_of_A = divisors(length($A)); - │ my %divisors_of_B = divisors(length($B)); + │ my %divisors_of_A = divisors($A); + │ my %divisors_of_B = divisors($B); │ my @common_divisors; │ foreach my $num (sort { $a <=> $b } keys %divisors_of_A) { │ push @common_divisors, $num @@ -87,76 +55,6 @@ Table of Contents │ } │ return %divisors; │ } - └──── - - We check if any subset of `$A' joins to make `$B'. - ┌──── - │ my @common; │ - │ foreach my $num (@common_divisors){ - │ my $tmp; - │ my $base = substr($A, 0, $num); - │ foreach (1 ... length($B) / $num) { - │ $tmp .= $base; - │ } - │ push @common, $base if $tmp eq $B; - │ } - │ - │ print "No common base string.\n" and exit 0 - │ unless scalar @common; - │ print join(', ', @common), "\n"; - └──── - - -2 Task 2 - Frequency Sort -═════════════════════════ - - You are given file named input. - - Write a script to find the frequency of all the words. - - It should print the result as first column of each line should be the - frequency of the the word followed by all the words of that frequency - arranged in lexicographical order. Also sort the words in the - ascending order of frequency. - - For the sake of this task, please ignore the following in the input - file: `. " ( ) , 's --' - - -2.1 Perl -──────── - - • Program: - - Swap unwanted characters with a space. - ┌──── - │ my $file = path(shift @ARGV)->slurp; - │ - │ $file =~ s/(--|'s)/ /g; - │ $file =~ s/[."(),]+/ /g; - │ $file =~ s/ / /g; - │ $file =~ s/\n/ /g; - └──── - - Get frequency of each word. - ┌──── - │ my %words; - │ foreach my $word (split / /, $file) { - │ $words{$word} = 1 and next unless exists $words{$word}; - │ $words{$word}++; - │ } - └──── - - Format the output. - ┌──── - │ my %out; - │ foreach my $word (sort keys %words) { - │ my $freq = $words{$word}; - │ push @{$out{$freq}}, $word; - │ } - │ - │ foreach my $freq (sort { $a <=> $b} keys %out) { - │ print "$freq ", join(' ', @{$out{$freq}}, "\n"); - │ } + │ print join(', ', @common_divisors), "\n"; └──── diff --git a/challenge-082/andinus/blog-1.txt b/challenge-082/andinus/blog-1.txt new file mode 100644 index 0000000000..770aa38b8d --- /dev/null +++ b/challenge-082/andinus/blog-1.txt @@ -0,0 +1 @@ +https://andinus.tilde.institute/pwc/challenge-082/ diff --git a/challenge-082/andinus/perl/ch-1.pl b/challenge-082/andinus/perl/ch-1.pl new file mode 100755 index 0000000000..6dfa71fa0f --- /dev/null +++ b/challenge-082/andinus/perl/ch-1.pl @@ -0,0 +1,33 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +die "usage: ./ch-1.pl " + unless scalar @ARGV == 2; + +my $A = shift @ARGV; +my $B = shift @ARGV; + +# Get all common divisors. +my %divisors_of_A = divisors($A); +my %divisors_of_B = divisors($B); +my @common_divisors; +foreach my $num (sort { $a <=> $b } keys %divisors_of_A) { + push @common_divisors, $num + if exists $divisors_of_B{$num}; +} + +# Returns all divisors of a number. +sub divisors { + my $n = shift @_; + my %divisors; + foreach my $i ( 1 ... $n){ + if ($n % $i == 0) { + $divisors{$i} = 1; + } + } + return %divisors; +} + +print join(', ', @common_divisors), "\n"; -- cgit From 8bba3e7e8e995db61fee11799e7363688fe2aba0 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 12 Oct 2020 11:51:12 +0200 Subject: Raku solutions 082-1 and 082-2 by ash --- challenge-082/ash/raku/ch-1.raku | 16 ++++++++++++++++ challenge-082/ash/raku/ch-2.raku | 23 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 challenge-082/ash/raku/ch-1.raku create mode 100644 challenge-082/ash/raku/ch-2.raku diff --git a/challenge-082/ash/raku/ch-1.raku b/challenge-082/ash/raku/ch-1.raku new file mode 100644 index 0000000000..f6aaef2abe --- /dev/null +++ b/challenge-082/ash/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku +# +# Task 1 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-082/ + +# Test runs: +# $ raku ch-1.raku 12 18 +# (1 2 3 6) +# $ raku ch-1.raku 100 500 +# (1 2 4 5 10 20 25 50 100) +# $ raku ch-1.raku 18 23 +# (1) + +my ($a, $b) = @*ARGS; + +say ((1 .. ($a max $b)).grep: $a %% *).grep: $b %% *; diff --git a/challenge-082/ash/raku/ch-2.raku b/challenge-082/ash/raku/ch-2.raku new file mode 100644 index 0000000000..0c95ea66fb --- /dev/null +++ b/challenge-082/ash/raku/ch-2.raku @@ -0,0 +1,23 @@ +#!/usr/bin/env raku +# +# Task 2 from +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-082/ + +unit sub MAIN(Str $a, Str $b, Str $c); + +my @parts; +for ^$a.chars -> $pos { + say 1 and return if $c eq $a.substr(0, $pos) ~ $b ~ $a.substr($pos); +} + +# Not sure if the below tests agree with the idea of the task. + +say 2 and return if $c eq $a ~ $b; + +for ^$b.chars -> $pos { + say 3 and return if $c eq $b.substr(0, $pos) ~ $a ~ $b.substr($pos); +} + +say 4 and return if $c eq $b ~ $a; + +say 0; -- cgit From 34ffa543b02e35a80e91461bef167732eb224704 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Mon, 12 Oct 2020 21:38:03 +0900 Subject: a solution of 082.1 in Raku --- challenge-082/gugod/raku/ch-1.raku | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 challenge-082/gugod/raku/ch-1.raku diff --git a/challenge-082/gugod/raku/ch-1.raku b/challenge-082/gugod/raku/ch-1.raku new file mode 100644 index 0000000000..f2d918b47b --- /dev/null +++ b/challenge-082/gugod/raku/ch-1.raku @@ -0,0 +1,10 @@ +#!/usr/bin/env raku + +sub MAIN (Int $M, Int $N) { + my ($a, $b) = ($M, $N).sort; + say common-factors($a, $b); +} + +sub common-factors (Int $a, Int $b) { + (1, 2..$a/2, $a).flat.grep(-> $n { 0 == $a % $n == $b % $n }); +} -- cgit From 93e729872243499407d495846097b5d6488d94ea Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Mon, 12 Oct 2020 14:11:02 +0100 Subject: Solutions for challenge 82. --- challenge-082/roger-bell-west/perl/ch-1.pl | 38 +++++++++++++++++++++ challenge-082/roger-bell-west/perl/ch-2.pl | 32 ++++++++++++++++++ challenge-082/roger-bell-west/python/ch-1.py | 40 +++++++++++++++++++++++ challenge-082/roger-bell-west/python/ch-2.py | 37 +++++++++++++++++++++ challenge-082/roger-bell-west/raku/ch-1.p6 | 32 ++++++++++++++++++ challenge-082/roger-bell-west/raku/ch-2.p6 | 31 ++++++++++++++++++ challenge-082/roger-bell-west/ruby/ch-1.rb | 49 ++++++++++++++++++++++++++++ challenge-082/roger-bell-west/ruby/ch-2.rb | 45 +++++++++++++++++++++++++ 8 files changed, 304 insertions(+) create mode 100755 challenge-082/roger-bell-west/perl/ch-1.pl create mode 100755 challenge-082/roger-bell-west/perl/ch-2.pl create mode 100755 challenge-082/roger-bell-west/python/ch-1.py create mode 100755 challenge-082/roger-bell-west/python/ch-2.py create mode 100755 challenge-082/roger-bell-west/raku/ch-1.p6 create mode 100755 challenge-082/roger-bell-west/raku/ch-2.p6 create mode 100755 challenge-082/roger-bell-west/ruby/ch-1.rb create mode 100755 challenge-082/roger-bell-west/ruby/ch-2.rb diff --git a/challenge-082/roger-bell-west/perl/ch-1.pl b/challenge-082/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..52d220c256 --- /dev/null +++ b/challenge-082/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,38 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 5; + +is_deeply(factor(12),{1 => 1, 2 => 1, 3 => 1, 4 => 1, 6 => 1, 12 => 1},'twelve'); +is_deeply(factor(18),{1 => 1, 2 => 1, 3 => 1, 6 => 1, 9 => 1, 18 => 1},'eighteen'); +is_deeply(factor(23),{1 => 1, 23 => 1},'twenty-three'); + +is_deeply(commonfactor(12,18),[1,2,3,6],'twelve-eighteen'); +is_deeply(commonfactor(18,23),[1],'twelve-twentythree'); + +sub factor { + my $n=shift; + my %o=map {$_ => 1} (1,$n); + foreach my $i (2..int(sqrt($n))) { + if ($n % $i == 0) { + $o{$n/$i}=$o{$i}=1; + } + } + return \%o; +} + +sub commonfactor { + my @f=map {factor($_)} @_; + my $s=shift @f; + while (@f) { + my $q=shift @f; + foreach my $f (keys %{$s}) { + unless (exists $q->{$f}) { + delete $s->{$f}; + } + } + } + return [sort keys %{$s}]; +} diff --git a/challenge-082/roger-bell-west/perl/ch-2.pl b/challenge-082/roger-bell-west/perl/ch-2.pl new file mode 100755 index 0000000000..30b078022a --- /dev/null +++ b/challenge-082/roger-bell-west/perl/ch-2.pl @@ -0,0 +1,32 @@ +#! /usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 5; + +is(isinterleave(qw(XY X XXY)),1,'example 1'); +is(isinterleave(qw(XXY XXZ XXXXZY)),1,'example 2'); +is(isinterleave(qw(YX X XXY)),0,'example 3'); +is(isinterleave(qw(ACF BDEG ABCDEFG)),1,'example 4'); +is(isinterleave(qw(ACF BDGE ABCDEFG)),0,'example 5'); + +sub isinterleave { + my ($a,$b,$c)=@_; + my @s=(map {[split '',$_]} ($a,$b,$c)); + my @l=map {$#{$_}} @s; + my @buf=([0,0,0]); + while (@buf) { + my $n=shift @buf; + if ($n->[2] > $l[2]) { + return 1; + } + if ($n->[0] <= $l[0] && $s[0][$n->[0]] eq $s[2][$n->[2]]) { + push @buf,[$n->[0]+1,$n->[1],$n->[2]+1]; + } + if ($n->[1] <= $l[1] && $s[1][$n->[1]] eq $s[2][$n->[2]]) { + push @buf,[$n->[0],$n->[1]+1,$n->[2]+1]; + } + } + return 0; +} diff --git a/challenge-082/roger-bell-west/python/ch-1.py b/challenge-082/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..88e8cc4399 --- /dev/null +++ b/challenge-082/roger-bell-west/python/ch-1.py @@ -0,0 +1,40 @@ +#! /usr/bin/python3 + +import unittest +from math import sqrt + +def factor(n): + o=set() + o.add(1) + o.add(n) + for i in range(2,int(sqrt(n))+1): + if (n % i == 0): + o.add(int(n/i)) + o.add(i) + return o + +def commonfactor(*fs): + f=list(map(factor,fs)) + s=f.pop(); + while (f): + s = s & f.pop() + return sorted(s) + +class TestCf(unittest.TestCase): + + def test_f1(self): + self.assertEqual(factor(12),set((1,2,3,4,6,12)),'twelve') + + def test_f2(self): + self.assertEqual(factor(18),set((1,2,3,6,9,18)),'eighteen') + + def test_f3(self): + self.assertEqual(factor(23),set((1,23)),'twenty-three') + + def test_cf1(self): + self.assertEqual(commonfactor(12,18),[1,2,3,6],'twelve-eighteen') + + def test_cf2(self): + self.assertEqual(commonfactor(18,23),[1],'twelve-twentythree') + +unittest.main() diff --git a/challenge-082/roger-bell-west/python/ch-2.py b/challenge-082/roger-bell-west/python/ch-2.py new file mode 100755 index 0000000000..4b88c1acf0 --- /dev/null +++ b/challenge-082/roger-bell-west/python/ch-2.py @@ -0,0 +1,37 @@ +#! /usr/bin/python3 + +import unittest +from collections import deque + +def isinterleave(a,b,c): + l=list(map(len,(a,b,c))) + buf=deque() + buf.append([0,0,0]) + while (buf): + n=buf.popleft() + if (n[2] >= l[2]): + return 1 + if ((n[0] < l[0]) and (a[n[0]] == c[n[2]])): + buf.append([n[0]+1,n[1],n[2]+1]) + if ((n[1] < l[1]) and (b[n[1]] == c[n[2]])): + buf.append([n[0],n[1]+1,n[2]+1]) + return 0 + +class TestInterleave(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(isinterleave('XY','X','XXY'),1,'example 1') + + def test_ex2(self): + self.assertEqual(isinterleave('XXY','XXZ','XXXXZY'),1,'example 2') + + def test_ex3(self): + self.assertEqual(isinterleave('YX','X','XXY'),0,'example 3') + + def test_ex4(self): + self.assertEqual(isinterleave('ACF','BDEG','ABCDEFG'),1,'example 4') + + def test_ex5(self): + self.assertEqual(isinterleave('ACF','BDGE','ABCDEFG'),0,'example 5') + +unittest.main() diff --git a/challenge-082/roger-bell-west/raku/ch-1.p6 b/challenge-082/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..01207a3e42 --- /dev/null +++ b/challenge-082/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,32 @@ +#! /usr/bin/perl6 + +use Test; + +plan 5; + +is-deeply(factor(12),SetHash.new(1,2,3,4,6,12),'twelve'); +is-deeply(factor(18),SetHash.new(1,2,3,6,9,18),'eighteen'); +is-deeply(factor(23),SetHash.new(1,23),'twenty-three'); + +is-deeply(commonfactor(12,18),(1,2,3,6),'twelve-eighteen'); +is-deeply(commonfactor(18,23),(1,),'twelve-twentythree'); + +sub factor($n) { + my $o=SetHash.new(1,$n); + for 2..floor(sqrt($n)) -> $i { + if ($n % $i == 0) { + $o{Int.new($n/$i)}++; + $o{$i}++; + } + } + return $o; +} + +sub commonfactor { + my @f=map {factor($_)},@_; + my $s=shift @f; + while (@f) { + $s (&)= shift @f; + } + return $s.keys.sort; +} diff --git a/challenge-082/roger-bell-west/raku/ch-2.p6 b/challenge-082/roger-bell-west/raku/ch-2.p6 new file mode 100755 index 0000000000..8d468d02a3 --- /dev/null +++ b/challenge-082/roger-bell-west/raku/ch-2.p6 @@ -0,0 +1,31 @@ +#! /usr/bin/perl6 + +use Test; + +plan 5; + +is(isinterleave('XY','X','XXY'),1,'example 1'); +is(isinterleave('XXY','XXZ','XXXXZY'),1,'example 2'); +is(isinterleave('YX','X','XXY'),0,'example 3'); +is(isinterleave('ACF','BDEG','ABCDEFG'),1,'example 4'); +is(isinterleave('ACF','BDGE','ABCDEFG'),0,'example 5'); + +sub isinterleave { + my ($a,$b,$c)=@_; + my @s=(map {[$_.comb]}, ($a,$b,$c)); + my @l=map {$_.end},@s; + my @buf=([0,0,0],); + while (@buf) { + my $n=shift @buf; + if ($n.[2] > @l[2]) { + return 1; + } + if ($n.[0] <= @l[0] && @s[0][$n.[0]] eq @s[2][$n.[2]]) { + push @buf,[$n.[0]+1,$n.[1],$n.[2]+1]; + } + if ($n.[1] <= @l[1] && @s[1][$n.[1]] eq @s[2][$n.[2]]) { + push @buf,[$n.[0],$n.[1]+1,$n.[2]+1]; + } + } + return 0; +} diff --git a/challenge-082/roger-bell-west/ruby/ch-1.rb b/challenge-082/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..309176d51c --- /dev/null +++ b/challenge-082/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,49 @@ +#! /usr/bin/ruby + +require 'set' + +def factor(n) + o=Set.new([1,n]) + 2.upto(Math.sqrt(n).floor) do |i| + if (n % i == 0) + o.add(n/i) + o.add(i) + end + end + return o +end + +def commonfactor(*fs) + f=fs.map{|x| factor(x)} + s=f.pop + while (!f.empty?) + s = s & f.pop + end + return s.sort +end + +require 'test/unit' + +class TestCf < Test::Unit::TestCase + + def test_f1 + assert_equal(Set.new([1,2,3,4,6,12]),factor(12)) + end + + def test_f2 + assert_equal(Set.new([1,2,3,6,9,18]),factor(18)) + end + + def test_f3 + assert_equal(Set.new([1,23]),factor(23)) + end + + def test_cf1 + assert_equal([1,2,3,6],commonfactor(12,18)) + end + + def test_cf2 + assert_equal([1],commonfactor(18,23)) + end + +end diff --git a/challenge-082/roger-bell-west/ruby/ch-2.rb b/challenge-082/roger-bell-west/ruby/ch-2.rb new file mode 100755 index 0000000000..067bddb305 --- /dev/null +++ b/challenge-082/roger-bell-west/ruby/ch-2.rb @@ -0,0 +1,45 @@ +#! /usr/bin/ruby + +def isinterleave(a,b,c) + l=[a,b,c].map{|x| x.length} + buf=[[0,0,0]] + while (!buf.empty?) + n=buf.pop + if (n[2] >= l[2]) + return 1 + end + if ((n[0] < l[0]) and (a[n[0]] == c[n[2]])) + buf.push([n[0]+1,n[1],n[2]+1]) + end + if ((n[1] < l[1]) and (b[n[1]] == c[n[2]])) + buf.push([n[0],n[1]+1,n[2]+1]) + end + end + return 0 +end + +require 'test/unit' + +class TestInterleave < Test::Unit::TestCase + + def test_ex1 + assert_equal(isinterleave('XY','X','XXY'),1) + end + + def test_ex2 + assert_equal(isinterleave('XXY','XXZ','XXXXZY'),1) + end + + def test_ex3 + assert_equal(isinterleave('YX','X','XXY'),0) + end + + def test_ex4 + assert_equal(isinterleave('ACF','BDEG','ABCDEFG'),1) + end + + def test_ex5 + assert_equal(isinterleave('ACF','BDGE','ABCDEFG'),0) + end + +end -- cgit From b707333731dc13148cb3772e9fc236fcc55ec86b Mon Sep 17 00:00:00 2001 From: Simon Green Date: Mon, 12 Oct 2020 23:30:08 +1000 Subject: sgreen solution for challenge 082 --- challenge-082/sgreen/README.md | 4 +-- challenge-082/sgreen/blog.txt | 1 + challenge-082/sgreen/perl/ch-1.pl | 32 +++++++++++++++++++++++ challenge-082/sgreen/perl/ch-2.pl | 54 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 challenge-082/sgreen/blog.txt create mode 100755 challenge-082/sgreen/perl/ch-1.pl create mode 100755 challenge-082/sgreen/perl/ch-2.pl diff --git a/challenge-082/sgreen/README.md b/challenge-082/sgreen/README.md index fde0cedfbd..669247f1fc 100644 --- a/challenge-082/sgreen/README.md +++ b/challenge-082/sgreen/README.md @@ -1,3 +1,3 @@ -# The Weekly Challenge 081 +# The Weekly Challenge 082 -Solution by Simon Green. [Blog](https://dev.to/simongreennet/the-weekly-challenge-081-1jje) +Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-082-3a9d) diff --git a/challenge-082/sgreen/blog.txt b/challenge-082/sgreen/blog.txt new file mode 100644 index 0000000000..1d83fd2f39 --- /dev/null +++ b/challenge-082/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-082-3a9d diff --git a/challenge-082/sgreen/perl/ch-1.pl b/challenge-082/sgreen/perl/ch-1.pl new file mode 100755 index 0000000000..b97c8b0490 --- /dev/null +++ b/challenge-082/sgreen/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw(say); + +use List::Util qw(min); + +sub main { + my @values = @_; + my @factors = (); + + die "You must specify at least two values\n" if scalar(@values) < 2; + foreach (@values) { + die "Value '$_' is not a positive number\n" + unless /^[1-9][0-9]*$/; + } + + my $min = min(@values); + OUTER: foreach my $number ( 1 .. $min ) { + foreach my $value (@values) { + next OUTER if $value % $number; + } + + push @factors, $number; + } + + say join ', ', @factors; + +} + +main(@ARGV); diff --git a/challenge-082/sgreen/perl/ch-2.pl b/challenge-082/sgreen/perl/ch-2.pl new file mode 100755 index 0000000000..8931338799 --- /dev/null +++ b/challenge-082/sgreen/perl/ch-2.pl @@ -0,0 +1,54 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use feature qw(say); + +sub _remove_character { + my ( $c, $words ) = @_; + my @array = (); + + for my $i ( 0 .. $#$words ) { + # We've exhausted all the characters from this word. + next if $words->[$i] eq ''; + + # The first remaining letter in this word is not what we want. + next if substr( $words->[$i], 0, 1 ) ne $c; + + # Add to the array striping the letter we used for the word. + push @array, + [ map { $_ == $i ? substr( $words->[$_], 1 ) : $words->[$_] } + 0 .. $#$words ]; + } + return @array; +} + +sub main { + my @words = @_; + my $target = pop(@words); + + # Sanity check + die "You must enter at least three strings" unless scalar(@words) >= 2; + + # If the length of the target is not the sum of the other + # strings, we can exit early + return 0 if length($target) != length( join( '', @words ) ); + + my @remaining = ( \@words ); + for my $i ( 1 .. length($target) ) { + # What character we are trying to match + my $c = substr( $target, $i - 1, 1 ); + + # See if any of the current solutions are still valid by + # matching the character + @remaining = map { _remove_character( $c, $_ ) } @remaining; + + # There are no possible solutions + return 0 if scalar(@remaining) == 0; + } + + # We've reached the target! + return 1; +} + +say main(@ARGV); -- cgit From f3c2e22b5fdb3804c142f85fc6f9b9e375b424d0 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Tue, 13 Oct 2020 00:09:51 +0900 Subject: a solution of 082.2 in raku --- challenge-082/gugod/raku/ch-2.raku | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 challenge-082/gugod/raku/ch-2.raku diff --git a/challenge-082/gugod/raku/ch-2.raku b/challenge-082/gugod/raku/ch-2.raku new file mode 100644 index 0000000000..047c4e0c4d --- /dev/null +++ b/challenge-082/gugod/raku/ch-2.raku @@ -0,0 +1,32 @@ +#!/usr/bin/env raku + +sub MAIN (Str $A, Str $B, Str $C) { + say interleaves($A, $B, $C) ?? 1 !! 0; +} + +sub interleaves (Str $A, Str $B, Str $C) { + my @stash; + @stash.push([-1, -1]); + + my $i = 0; + while $i < $C.chars && @stash.elems > 0 { + my $c = $C.substr($i++, 1); + my @stash2 = gather { + while @stash.elems > 0 { + my $it = @stash.pop(); + my $a = $A.substr($it[0]+1, 1); + my $b = $B.substr($it[1]+1, 1); + if $c eq $a { + take [$it[0]+1, $it[1]]; + } + if $c eq $b { + take [$it[0], $it[1]+1]; + } + } + }; + + @stash = @stash2.unique(:with(&[eqv])); + } + + return $i == $C.chars && @stash.elems > 0 && @stash[0][0].succ == $A.chars && @stash[0][1].succ == $B.chars; +} -- cgit From feeb88b3fbce653093eabb00911f992a23a1ed0c Mon Sep 17 00:00:00 2001 From: Steven Wilson Date: Mon, 12 Oct 2020 17:28:35 +0100 Subject: add solution week 82 task 1 --- challenge-082/steven-wilson/perl/ch-1.pl | 58 ++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 challenge-082/steven-wilson/perl/ch-1.pl diff --git a/challenge-082/steven-wilson/perl/ch-1.pl b/challenge-082/steven-wilson/perl/ch-1.pl new file mode 100644 index 0000000000..92ca88a1de --- /dev/null +++ b/challenge-082/steven-wilson/perl/ch-1.pl @@ -0,0 +1,58 @@ +#!/usr/bin/env perl +# Week 82 Task 1 solution by Steven Wilson. + +=encoding utf8 + +=head1 TASK #1 › Common Factors +Submitted by: Niels van Dijke + +You are given 2 positive numbers $M and $N. + +Write a script to list all common factors of the given numbers. +Example 1: + +Input: + $M = 12 + $N = 18 + +Output: + (1, 2, 3, 6) + +Explanation: + Factors of 12: 1, 2, 3, 4, 6 + Factors of 18: 1, 2, 3, 6, 9 + +Example 2: + +Input: + $M = 18 + $N = 23 + +Output: + (1) + +Explanation: + Factors of 18: 1, 2, 3, 6, 9 + Factors of 23: 1 +=cut + +use strict; +use warnings; +use Test::More; +use Math::Factor::XS qw/ factors /; + +my @e1_t = qw/ 1 2 3 6 /; +my @e2_t = qw/ 1 /; +is_deeply( common_factors( 12, 18 ), \@e1_t, 'example 1' ); +is_deeply( common_factors( 18, 23 ), \@e2_t, 'example 2' ); +done_testing(); + +sub common_factors { + my ( $first, $second ) = @_; + my %first_factors = map { $_ => 1 } factors($first); + my @second_factors = factors($second); + my @intersection = sort { $a <=> $b } + grep { exists $first_factors{$_} } @second_factors; + unshift @intersection, 1; + return \@intersection; +} -- cgit From c78b0bc39325716be74af76ba1d6462f20ed63d5 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Mon, 12 Oct 2020 10:41:11 -0600 Subject: initial --- challenge-082/mark-anderson/raku/ch-2.p6 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/challenge-082/mark-anderson/raku/ch-2.p6 b/challenge-082/mark-anderson/raku/ch-2.p6 index 1d67d02a79..91a0e6a188 100644 --- a/challenge-082/mark-anderson/raku/ch-2.p6 +++ b/challenge-082/mark-anderson/raku/ch-2.p6 @@ -9,11 +9,11 @@ my @terms := |from-json "terms.json".IO.slurp; say interleaved($A, $B, $C); -sub interleaved($S1, $S2, $C) { - for ($S1, $S2), ($S2, $S1) -> ($A, $B) { - for @terms[$A.chars].Array X @terms[$B.chars].Array -> (@A, @B) { - return 1 if roundrobin($A.comb.rotor(@A), $B.comb.rotor(@B)) - .flat.join eq $C; +sub interleaved($A, $B, $C) { + for @terms[$A.chars].Array X @terms[$B.chars].Array -> (@A, @B) { + for (($A, $B, @A, @B), ($B, $A, @B, @A)) -> ($S1, $S2, @A1, @A2) { + return 1 if roundrobin($S1.comb.rotor(@A1), $S2.comb.rotor(@A2)) + .flat.join eq $C; } } -- cgit From cc0c12f498059a1cbf12e04382d6678281ace363 Mon Sep 17 00:00:00 2001 From: Mark Anderson Date: Mon, 12 Oct 2020 10:45:29 -0600 Subject: initial --- challenge-082/mark-anderson/raku/ch-2.p6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-082/mark-anderson/raku/ch-2.p6 b/challenge-082/mark-anderson/raku/ch-2.p6 index 91a0e6a188..be03ab8fae 100644 --- a/challenge-082/mark-anderson/raku/ch-2.p6 +++ b/challenge-082/mark-anderson/raku/ch-2.p6 @@ -11,7 +11,7 @@ say interleaved($A, $B, $C); sub interleaved($A, $B, $C) { for @terms[$A.chars].Array X @terms[$B.chars].Array -> (@A, @B) { - for (($A, $B, @A, @B), ($B, $A, @B, @A)) -> ($S1, $S2, @A1, @A2) { + for ($A, $B, @A, @B), ($B, $A, @B, @A) -> ($S1, $S2, @A1, @A2) { return 1 if roundrobin($S1.comb.rotor(@A1), $S2.comb.rotor(@A2)) .flat.join eq $C; } -- cgit From 2369a61c4807f2f758f6df0c64a9faa9bc8b233d Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Mon, 12 Oct 2020 21:57:18 +0200 Subject: initial --- challenge-082/markus-holzer/raku/ch-1.raku | 3 +++ challenge-082/markus-holzer/raku/ch-2.raku | 0 2 files changed, 3 insertions(+) create mode 100644 challenge-082/markus-holzer/raku/ch-1.raku create mode 100644 challenge-082/markus-holzer/raku/ch-2.raku diff --git a/challenge-082/markus-holzer/raku/ch-1.raku b/challenge-082/markus-holzer/raku/ch-1.raku new file mode 100644 index 0000000000..4b5f234cda --- /dev/null +++ b/challenge-082/markus-holzer/raku/ch-1.raku @@ -0,0 +1,3 @@ +unit sub MAIN( Int $N, Int $M ); + +say "({ join ', ', grep all( $N, $M ) %% *, 1 ..^ max $N, $M })" \ No newline at end of file diff --git a/challenge-082/markus-holzer/raku/ch-2.raku b/challenge-082/markus-holzer/raku/ch-2.raku new file mode 100644 index 0000000000..e69de29bb2 -- cgit From 6b828aefdf389ce21b0f58586e859bec654d5cd1 Mon Sep 17 00:00:00 2001 From: "Markus \"Holli\" Holzer" Date: Mon, 12 Oct 2020 22:00:11 +0200 Subject: initial --- challenge-082/markus-holzer/raku/ch-2.raku | 3 +++ 1 file changed, 3 insertions(+) diff --git a/challenge-082/markus-holzer/raku/ch-2.raku b/challenge-082/markus-holzer/raku/ch-2.raku index e69de29bb2..56d47ff51d 100644 --- a/challenge-082/markus-holzer/raku/ch-2.raku +++ b/challenge-082/markus-holzer/raku/ch-2.raku @@ -0,0 +1,3 @@ +unit sub MAIN( Str $A, Str $B, Str $C where $C.chars == $A.chars + $B.chars ); + +say +so grep { $C eq [~] $A.substr( 0, $^i ), $B, $A.substr( $^i ) }, ^$A.chars \ No newline at end of file -- cgit From 42583b076195a2114e9635352d77898bf8345ba2 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 12 Oct 2020 23:54:55 +0200 Subject: Add solutions to 082 by E. Choroba --- challenge-082/e-choroba/perl5/ch-1.pl | 23 +++++++++++++++++++ challenge-082/e-choroba/perl5/ch-2.pl | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 challenge-082/e-choroba/perl5/ch-1.pl create mode 100755 challenge-082/e-choroba/perl5/ch-2.pl diff --git a/challenge-082/e-choroba/perl5/ch-1.pl b/challenge-082/e-choroba/perl5/ch-1.pl new file mode 100755 index 0000000000..bac0ff5500 --- /dev/null +++ b/challenge-082/e-choroba/perl5/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub common_factors { + my ($m, $n) = @_; + ($m, $n) = ($n, $m) if $n < $m; + my @r; + for my $i (1 .. $m) { + push @r, $i if 0 == $m % $i + && 0 == $n % $i; + } + return \@r +} + +use Test::More; + +is_deeply common_factors(12, 18), [1, 2, 3, 6], 'Example 1'; +is_deeply common_factors(18, 23), [1], 'Example 2'; +is_deeply common_factors(123_456_789, 987_654_321), [1, 3, 9], 'large numbers'; + +done_testing(); + diff --git a/challenge-082/e-choroba/perl5/ch-2.pl b/challenge-082/e-choroba/perl5/ch-2.pl new file mode 100755 index 0000000000..e61bbe3dd4 --- /dev/null +++ b/challenge-082/e-choroba/perl5/ch-2.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +use warnings; +use strict; + +sub interleave_string { + my ($x, $y, $z) = @_; + return 0 if length($z) != length($x) + length($y); + + return 1 if "" eq $z; + + my ($first_x, $first_y, $first_z) = map { substr $_, 0, 1 } $x, $y, $z; + + my $maybe_x = $first_x eq $first_z; + my $maybe_y = $first_y eq $first_z; + + my $rest_x = $maybe_x ? substr $x, 1 : ""; + my $rest_y = $maybe_y ? substr $y, 1 : ""; + my $rest_z = substr $z, 1; + + if ($maybe_x && $maybe_y) { + return interleave_string($rest_x, $y, $rest_z) + || interleave_string($x, $rest_y, $rest_z) + } + + return interleave_string($rest_x, $y, $rest_z) if $maybe_x; + + return interleave_string($x, $rest_y, $rest_z) if $maybe_y; + + return 0 +} + +use Test::More; + +is interleave_string('XY', 'X', 'XXY'), 1, 'Example 1'; +is interleave_string('XXY', 'XXZ', 'XXXXZY'), 1, 'Example 2'; +is interleave_string('YX', 'X', 'XXY'), 0, 'Example 3'; + +is interleave_string('ABC', 'BD', $_), 1, $_ + for qw( ABDBC ABCBD ABBCD ABBDC BABCD BABDC BADBC BDABC ); + + +done_testing(); -- cgit From d4329929f3bf5cfbaa043684069fa1a7681391da Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 13 Oct 2020 05:17:11 +0100 Subject: - Added solutions by Mark Anderson. --- stats/pwc-challenge-081.json | 717 ++++++++++++++++++++++++++++ stats/pwc-current.json | 702 +--------------------------- stats/pwc-language-breakdown-summary.json | 34 +- stats/pwc-language-breakdown.json | 547 +++++++++++----------- stats/pwc-leaders.json | 746 +++++++++++++++--------------- stats/pwc-summary-1-30.json | 108 ++--- stats/pwc-summary-121-150.json | 106 ++--- stats/pwc-summary-151-180.json | 106 ++--- stats/pwc-summary-181-210.json | 28 +- stats/pwc-summary-31-60.json | 92 ++-- stats/pwc-summary-61-90.json | 58 +-- stats/pwc-summary-91-120.json | 104 ++--- stats/pwc-summary.json | 42 +- 13 files changed, 1738 insertions(+), 1652 deletions(-) create mode 100644 stats/pwc-challenge-081.json diff --git a/stats/pwc-challenge-081.json b/stats/pwc-challenge-081.json new file mode 100644 index 0000000000..fbf2a1a5fd --- /dev/null +++ b/stats/pwc-challenge-081.json @@ -0,0 +1,717 @@ +{ + "drilldown" : { + "series" : [ + { + "id" : "Abigail", + "name" : "Abigail", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Adam Russell", + "id" : "Adam Russell" + }, + { + "id" : "Alexander Pankoff", + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Alexander Pankoff" + }, + { + "id" : "Andinus", + "name" : "Andinus", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" + }, + { + "id" : "Arne Sommer", + "data" : [ + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Arne Sommer" + }, + { + "name" : "Athanasius", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Athanasius" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Bob Lied", + "id" : "Bob Lied" + }, + { + "name" : "Cheok-Yin Fung", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Cheok-Yin Fung" + }, + { + "id" : "Colin Crain", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Colin Crain" + }, + { + "id" : "Dave Jacoby", + "name" : "Dave Jacoby", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Duncan C. White", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Duncan C. White" + }, + { + "name" : "E. Choroba", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "E. Choroba" + }, + { + "id" : "Flavio Poletti", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Flavio Poletti" + }, + { + "name" : "Jaldhar H. Vyas", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Jaldhar H. Vyas" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "James Smith", + "id" : "James Smith" + }, + { + "name" : "Jan Krnavek", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Jan Krnavek" + }, + { + "name" : "Jorg Sommrey", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Jorg Sommrey" + }, + { + "id" : "Jose Luis", + "name" : "Jose Luis", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Julio de Castro", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ] + ], + "id" : "Julio de Castro" + }, + { + "name" : "Kang-min Liu", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Kang-min Liu" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Lars Thegler", + "id" : "Lars Thegler" + }, + { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Laurent Rosenfeld", + "id" : "Laurent Rosenfeld" + }, + { + "name" : "Lubos Kolouch", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Lubos Kolouch" + }, + { + "name" : "Mark Anderson", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Mark Anderson" + }, + { + "id" : "Markus Holzer", + "name" : "Markus Holzer", + "data" : [ + [ + "Raku", + 2 + ] + ] + }, + { + "id" : "Mohammad S Anwar", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Mohammad S Anwar" + }, + { + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 2 + ] + ], + "name" : "Myoungjin Jeon", + "id" : "Myoungjin Jeon" + }, + { + "name" : "Niels van Dijke", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Niels van Dijke" + }, + { + "name" : "Nuno Vieira", + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Nuno Vieira" + }, + { + "id" : "Pete Houston", + "name" : "Pete Houston", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "name" : "Roger Bell_West", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "id" : "Roger Bell_West" + }, + { + "id" : "Shawn Wagner", + "name" : "Shawn Wagner", + "data" : [ + [ + "Perl", + 2 + ] + ] + }, + { + "id" : "Simon Green", + "name" : "Simon Green", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ] + }, + { + "name" : "Simon Proctor", + "data" : [ + [ + "Raku", + 2 + ] + ], + "id" : "Simon Proctor" + }, + { + "id" : "Ulrich Rieke", + "name" : "Ulrich Rieke", + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ] + }, + { + "name" : "Vinod Kumar K", + "data" : [ + [ + "Perl", + 1 + ] + ], + "id" : "Vinod Kumar K" + }, + { + "id" : "Walt Mankowski", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Walt Mankowski" + }, + { + "id" : "Wanderdoc", + "data" : [ + [ + "Perl", + 2 + ] + ], + "name" : "Wanderdoc" + } + ] + }, + "series" : [ + { + "name" : "Perl Weekly Challenge - 081", + "data" : [ + { + "drilldown" : "Abigail", + "y" : 2, + "name" : "Abigail" + }, + { + "name" : "Adam Russell", + "y" : 3, + "drilldown" : "Adam Russell" + }, + { + "name" : "Alexander Pankoff", + "y" : 2, + "drilldown" : "Alexander Pankoff" + }, + { + "drilldown" : "Andinus", + "y" : 4, + "name" : "Andinus" + }, + { + "y" : 2, + "drilldown" : "Andrew Shitov", + "name" : "Andrew Shitov" + }, + { + "name" : "Arne Sommer", + "y" : 3, + "drilldown" : "Arne Sommer" + }, + { + "name" : "Athanasius", + "y" : 4, + "drilldown" : "Athanasius" + }, + { + "drilldown" : "Bob Lied", + "y" : 2, + "name" : "Bob Lied" + }, + { + "name" : "Cheok-Yin Fung", + "y" : 2, + "drilldown" : "Cheok-Yin Fung" + }, + { + "name" : "Colin Crain", + "y" : 5, + "drilldown" : "Colin Crain" + }, + { + "name" : "Dave Jacoby", + "y" : 2, + "drilldown" : "Dave Jacoby" + }, + { + "y" : 2, + "drilldown" : "Duncan C. White", + "name" : "Duncan C. White" + }, + { + "drilldown" : "E. Choroba", + "y" : 2, + "name" : "E. Choroba" + }, + { + "y" : 4, + "drilldown" : "Flavio Poletti", + "name" : "Flavio Poletti" + }, + { + "y" : 5, + "drilldown" : "Jaldhar H. Vyas", + "name" : "Jaldhar H. Vyas" + }, + { + "name" : "James Smith", + "drilldown" : "James Smith", + "y" : 2 + }, + { + "name" : "Jan Krnavek", + "drilldown" : "Jan Krnavek", + "y" : 2 + }, + { + "y" : 2, + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "y" : 2, + "drilldown" : "Jose Luis", + "name" : "Jose Luis" + }, + { + "name" : "Julio de Castro", + "y" : 4, + "drilldown" : "Julio de Castro" + }, + { + "y" : 2, + "drilldown" : "Kang-min Liu", + "name" : "Kang-min Liu" + }, + { + "y" : 2, + "drilldown" : "Lars Thegler", + "name" : "Lars Thegler" + }, + { + "name" : "Laurent Rosenfeld", + "y" : 3, + "drilldown" : "Laurent Rosenfeld" + }, + { + "name" : "Lubos Kolouch", + "y" : 2, + "drilldown" : "Lubos Kolouch" + }, + { + "y" : 2, + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "y" : 2, + "drilldown" : "Markus Holzer", + "name" : "Markus Holzer" + }, + { + "name" : "Mohammad S Anwar", + "y" : 5, + "drilldown" : "Mohammad S Anwar" + }, + { + "name" : "Myoungjin Jeon", + "drilldown" : "Myoungjin Jeon", + "y" : 6 + }, + { + "drilldown" : "Niels van Dijke", + "y" : 2, + "name" : "Niels van Dijke" + }, + { + "drilldown" : "Nuno Vieira", + "y" : 2, + "name" : "Nuno Vieira" + }, + { + "drilldown" : "Pete Houston", + "y" : 2, + "name" : "Pete Houston" + }, + { + "drilldown" : "Roger Bell_West", + "y" : 5, + "name" : "Roger Bell_West" + }, + { + "name" : "Shawn Wagner", + "drilldown" : "Shawn Wagner", + "y" : 2 + }, + { + "drilldown" : "Simon Green", + "y" : 3, + "name" : "Simon Green" + }, + { + "name" : "Simon Proctor", + "drilldown" : "Simon Proctor", + "y" : 2 + }, + { + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke", + "y" : 2 + }, + { + "drilldown" : "Vinod Kumar K", + "y" : 1, + "name" : "Vinod Kumar K" + }, + { + "drilldown" : "Walt Mankowski", + "y" : 3, + "name" : "Walt Mankowski" + }, + { + "drilldown" : "Wanderdoc", + "y" : 2, + "name" : "Wanderdoc" + } + ], + "colorByPoint" : 1 + } + ], + "title" : { + "text" : "Perl Weekly Challenge - 081" + }, + "subtitle" : { + "text" : "[Champions: 39] Last updated at 2020-10-13 04:16:38 GMT" + }, + "tooltip" : { + "pointFormat" : "{point.name}: {point.y:f}
", + "headerFormat" : "{series.name}
", + "followPointer" : 1 + }, + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } + } + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "xAxis" : { + "type" : "category" + }, + "chart" : { + "type" : "column" + }, + "legend" : { + "enabled" : 0 + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index acc953ba22..cad4c39b19 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,506 +1,30 @@ { + "chart" : { + "type" : "column" + }, "xAxis" : { "type" : "category" }, "series" : [ { - "name" : "Perl Weekly Challenge - 081", "data" : [ { + "name" : "Mark Anderson", "y" : 2, - "name" : "Abigail", - "drilldown" : "Abigail" - }, - { - "y" : 3, - "name" : "Adam Russell", - "drilldown" : "Adam Russell" - }, - { - "name" : "Alexander Pankoff", - "drilldown" : "Alexander Pankoff", - "y" : 2 - }, - { - "name" : "Andinus", - "drilldown" : "Andinus", - "y" : 4 - }, - { - "y" : 2, - "name" : "Andrew Shitov", - "drilldown" : "Andrew Shitov" - }, - { - "y" : 3, - "name" : "Arne Sommer", - "drilldown" : "Arne Sommer" - }, - { - "y" : 4, - "name" : "Athanasius", - "drilldown" : "Athanasius" - }, - { - "drilldown" : "Bob Lied", - "name" : "Bob Lied", - "y" : 2 - }, - { - "drilldown" : "Cheok-Yin Fung", - "name" : "Cheok-Yin Fung", - "y" : 2 - }, - { - "y" : 5, - "name" : "Colin Crain", - "drilldown" : "Colin Crain" - }, - { - "y" : 2, - "name" : "Dave Jacoby", - "drilldown" : "Dave Jacoby" - }, - { - "drilldown" : "Duncan C. White", - "name" : "Duncan C. White", - "y" : 2 - }, - { - "drilldown" : "E. Choroba", - "name" : "E. Choroba", - "y" : 2 - }, - { - "name" : "Flavio Poletti", - "drilldown" : "Flavio Poletti", - "y" : 4 - }, - { - "y" : 5, - "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas" - }, - { - "y" : 2, - "drilldown" : "James Smith", - "name" : "James Smith" - }, - { - "y" : 2, - "drilldown" : "Jan Krnavek", - "name" : "Jan Krnavek" - }, - { - "drilldown" : "Jorg Sommrey", - "name" : "Jorg Sommrey", - "y" : 2 - }, - { - "y" : 2, - "name" : "Jose Luis", - "drilldown" : "Jose Luis" - }, - { - "name" : "Julio de Castro", - "drilldown" : "Julio de Castro", - "y" : 4 - }, - { - "name" : "Kang-min Liu", - "drilldown" : "Kang-min Liu", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Lars Thegler", - "name" : "Lars Thegler" - }, - { - "drilldown" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld", - "y" : 3 - }, - { - "name" : "Lubos Kolouch", - "drilldown" : "Lubos Kolouch", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Mark Anderson", - "name" : "Mark Anderson" - }, - { - "drilldown" : "Markus Holzer", - "name" : "Markus Holzer", - "y" : 2 - }, - { - "y" : 5, - "drilldown" : "Mohammad S Anwar", - "name" : "Mohammad S Anwar" - }, - { - "y" : 6, - "name" : "Myoungjin Jeon", - "drilldown" : "Myoungjin Jeon" - }, - { - "y" : 2, - "name" : "Niels van Dijke", - "drilldown" : "Niels van Dijke" - }, - { - "y" : 2, - "name" : "Nuno Vieira", - "drilldown" : "Nuno Vieira" - }, - { - "drilldown" : "Pete Houston", - "name" : "Pete Houston", - "y" : 2 - }, - { - "drilldown" : "Roger Bell_West", - "name" : "Roger Bell_West", - "y" : 5 - }, - { - "name" : "Shawn Wagner", - "drilldown" : "Shawn Wagner", - "y" : 2 - }, - { - "y" : 3, - "name" : "Simon Green", - "drilldown" : "Simon Green" - }, - { - "name" : "Simon Proctor", - "drilldown" : "Simon Proctor", - "y" : 2 - }, - { - "y" : 2, - "name" : "Ulrich Rieke", - "drilldown" : "Ulrich Rieke" - }, - { - "name" : "Vinod Kumar K", - "drilldown" : "Vinod Kumar K", - "y" : 1 - }, - { - "y" : 3, - "name" : "Walt Mankowski", - "drilldown" : "Walt Mankowski" - }, - { - "y" : 2, - "name" : "Wanderdoc", - "drilldown" : "Wanderdoc" + "drilldown" : "Mark Anderson" } ], + "name" : "Perl Weekly Challenge - 082",