aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorseaker <3043281+seaker@users.noreply.github.com>2021-05-10 23:36:02 +0800
committerseaker <3043281+seaker@users.noreply.github.com>2021-05-10 23:36:02 +0800
commitb82a359f9ab72a3160797bf2d0aba8a0b23fe6ed (patch)
treea00fb83ed6d531b3592a2501e03a6b02157236f8
parent144a4fa80fbfa1d1356d05d1da1a1e7ff4cd6ba9 (diff)
parent5e535c759ec1826d95b3f49c4033db88803975ca (diff)
downloadperlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.tar.gz
perlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.tar.bz2
perlweeklychallenge-club-b82a359f9ab72a3160797bf2d0aba8a0b23fe6ed.zip
Merge branch 'manwar:master' into master
-rw-r--r--challenge-018/lakpatashi/README1
-rwxr-xr-xchallenge-018/lakpatashi/perl/ch-2.pl45
-rw-r--r--challenge-019/lakpatashi/README1
-rwxr-xr-xchallenge-019/lakpatashi/perl/ch-2.pl24
-rw-r--r--challenge-020/lakpatashi/README1
-rwxr-xr-xchallenge-020/lakpatashi/perl/ch-1.pl22
-rwxr-xr-xchallenge-020/lakpatashi/perl/ch-2.pl38
-rw-r--r--challenge-112/luca-ferrari/blog-1.txt1
-rw-r--r--challenge-112/luca-ferrari/blog-2.txt1
-rw-r--r--challenge-112/luca-ferrari/raku/ch-1.p614
-rw-r--r--challenge-112/luca-ferrari/raku/ch-2.p626
-rw-r--r--challenge-112/mark-anderson/raku/ch-1.raku10
-rw-r--r--challenge-112/mark-anderson/raku/ch-2.raku137
-rwxr-xr-xchallenge-112/roger-bell-west/perl/ch-1.pl28
-rwxr-xr-xchallenge-112/roger-bell-west/perl/ch-2.pl20
-rwxr-xr-xchallenge-112/roger-bell-west/python/ch-1.py31
-rwxr-xr-xchallenge-112/roger-bell-west/python/ch-2.py26
-rwxr-xr-xchallenge-112/roger-bell-west/raku/ch-1.p626
-rwxr-xr-xchallenge-112/roger-bell-west/raku/ch-2.p618
-rwxr-xr-xchallenge-112/roger-bell-west/ruby/ch-1.rb39
-rwxr-xr-xchallenge-112/roger-bell-west/ruby/ch-2.rb31
-rwxr-xr-xchallenge-112/roger-bell-west/rust/ch-1.rs40
-rwxr-xr-xchallenge-112/roger-bell-west/rust/ch-2.rs29
-rw-r--r--stats/pwc-challenge-018.json279
-rw-r--r--stats/pwc-challenge-019.json557
-rw-r--r--stats/pwc-challenge-020.json311
-rw-r--r--stats/pwc-challenge-111.json593
-rw-r--r--stats/pwc-current.json592
-rw-r--r--stats/pwc-language-breakdown-summary.json58
-rw-r--r--stats/pwc-language-breakdown.json1609
-rw-r--r--stats/pwc-leaders.json792
-rw-r--r--stats/pwc-summary-1-30.json36
-rw-r--r--stats/pwc-summary-121-150.json46
-rw-r--r--stats/pwc-summary-151-180.json110
-rw-r--r--stats/pwc-summary-181-210.json110
-rw-r--r--stats/pwc-summary-211-240.json44
-rw-r--r--stats/pwc-summary-31-60.json32
-rw-r--r--stats/pwc-summary-61-90.json96
-rw-r--r--stats/pwc-summary-91-120.json42
-rw-r--r--stats/pwc-summary.json58
40 files changed, 3376 insertions, 2598 deletions
diff --git a/challenge-018/lakpatashi/README b/challenge-018/lakpatashi/README
new file mode 100644
index 0000000000..bc153bd576
--- /dev/null
+++ b/challenge-018/lakpatashi/README
@@ -0,0 +1 @@
+Solution by lakpatashi
diff --git a/challenge-018/lakpatashi/perl/ch-2.pl b/challenge-018/lakpatashi/perl/ch-2.pl
new file mode 100755
index 0000000000..de0fa545e0
--- /dev/null
+++ b/challenge-018/lakpatashi/perl/ch-2.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Data::Dumper;
+use List::Util qw(sum min);
+use feature qw(switch);
+
+#part 2
+my %priorityQ = (1 => ['apple','ball']);
+insert_with_priority(\%priorityQ,'cat',2);
+print pull_highest_priority_element(\%priorityQ),"\n";
+print pull_highest_priority_element(\%priorityQ),"\n";
+if( is_empty(\%priorityQ) ){
+ print "empty\n";
+}else{
+ print "not empty\n";
+}
+
+sub insert_with_priority{
+ #(pQ,ele,priority)
+ my ($pQ,$val,$key) = @_;
+ if( $pQ->{$key} ){ #if key exist
+ push( $pQ->{$key},$val );
+ }else{
+ $pQ->{$key} = [$val] ; #key doesn't exist
+ }
+}
+sub pull_highest_priority_element{
+ #(pQ)
+ my ($pQ) = @_;
+ my $key = min keys $pQ;
+ my $val = shift( $pQ->{$key} );
+ delete $pQ->{$key} unless @{$pQ->{$key}};
+ return $val;
+}
+
+sub is_empty{
+ #(pQ)
+ my ($pQ) = @_;
+ return not scalar %{$pQ};
+}
+
+print '='x10," P Queue ",'='x10,"\n";
+print Dumper \%priorityQ;
diff --git a/challenge-019/lakpatashi/README b/challenge-019/lakpatashi/README
new file mode 100644
index 0000000000..bc153bd576
--- /dev/null
+++ b/challenge-019/lakpatashi/README
@@ -0,0 +1 @@
+Solution by lakpatashi
diff --git a/challenge-019/lakpatashi/perl/ch-2.pl b/challenge-019/lakpatashi/perl/ch-2.pl
new file mode 100755
index 0000000000..ed7e298875
--- /dev/null
+++ b/challenge-019/lakpatashi/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Data::Dumper;
+use List::Util qw(sum);
+use feature qw(switch);
+
+#part 2
+my $str = "This is random string to be formatted and wrap to given length";
+my $LineWidth = 10;
+my $SpaceLeft = $LineWidth;
+my $SpaceWidth = 1;
+
+for my $word (split / /,$str){
+ if ( length($word) + $SpaceWidth > $SpaceLeft ){
+ #insert line break before Word in Text
+ print "\n$word";
+ $SpaceLeft = $LineWidth - length($word);
+ }else{
+ print " $word";
+ $SpaceLeft -= (length($word) + $SpaceWidth);
+ }
+}
diff --git a/challenge-020/lakpatashi/README b/challenge-020/lakpatashi/README
new file mode 100644
index 0000000000..bc153bd576
--- /dev/null
+++ b/challenge-020/lakpatashi/README
@@ -0,0 +1 @@
+Solution by lakpatashi
diff --git a/challenge-020/lakpatashi/perl/ch-1.pl b/challenge-020/lakpatashi/perl/ch-1.pl
new file mode 100755
index 0000000000..3cb4296154
--- /dev/null
+++ b/challenge-020/lakpatashi/perl/ch-1.pl
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Data::Dumper;
+use List::Util qw(sum);
+use feature qw(switch);
+
+#part 1
+my ($str) = shift;
+my @arr = split //,$str;
+my $char = shift @arr;
+print $char;
+for my $x (@arr){
+ if($x ne $char){
+ print " ";
+ $char = $x;
+ }
+ print $x;
+}
+
+
diff --git a/challenge-020/lakpatashi/perl/ch-2.pl b/challenge-020/lakpatashi/perl/ch-2.pl
new file mode 100755
index 0000000000..3e659002f8
--- /dev/null
+++ b/challenge-020/lakpatashi/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+use Data::Dumper;
+
+# part 2
+
+my %hash;
+
+my $n = 2;
+for (;;){
+ #print "checking:: $n\n";
+ my $val = divisorSum($n);
+ if( $val > 1 ){
+ if( divisorSum($val)==$n and $val != $n){
+ print "found min pair:: ($n,$val)\n";
+ last;
+ }
+ }
+ #print "$n\n";
+ last if $n == 1000;
+ $n++;
+}
+
+sub divisorSum{
+ my ($n)= @_;
+ my $divisorSum = 1;
+ for (2..int sqrt $n){
+ if ($_**2 == $n){
+ $divisorSum += $_;
+ }else{
+ $divisorSum += $_ + int $n/$_ unless $n % $_; # add if divisor
+ }
+ }
+ return $divisorSum;
+}
+
diff --git a/challenge-112/luca-ferrari/blog-1.txt b/challenge-112/luca-ferrari/blog-1.txt
new file mode 100644
index 0000000000..60c0a57573
--- /dev/null
+++ b/challenge-112/luca-ferrari/blog-1.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/05/10/PerlWeeklyChallenge112.html#task1
diff --git a/challenge-112/luca-ferrari/blog-2.txt b/challenge-112/luca-ferrari/blog-2.txt
new file mode 100644
index 0000000000..89da990e83
--- /dev/null
+++ b/challenge-112/luca-ferrari/blog-2.txt
@@ -0,0 +1 @@
+https://fluca1978.github.io/2021/05/10/PerlWeeklyChallenge112.html#task2
diff --git a/challenge-112/luca-ferrari/raku/ch-1.p6 b/challenge-112/luca-ferrari/raku/ch-1.p6
new file mode 100644
index 0000000000..b984a31b28
--- /dev/null
+++ b/challenge-112/luca-ferrari/raku/ch-1.p6
@@ -0,0 +1,14 @@
+#!raku
+
+sub MAIN( Str :$path ) {
+
+ my @results;
+ for $path.split( '/' ) {
+ next if ! $_ || $_ ~~ '.';
+ @results.push: $_ if ( $_ !~~ '..' );
+ @results = @results[ 0 .. * - 2 ] if $_ ~~ '..';
+
+ }
+
+ ('/' ~ @results.join( '/' )).say;
+}
diff --git a/challenge-112/luca-ferrari/raku/ch-2.p6 b/challenge-112/luca-ferrari/raku/ch-2.p6
new file mode 100644
index 0000000000..c735eb0a1a
--- /dev/null
+++ b/challenge-112/luca-ferrari/raku/ch-2.p6
@@ -0,0 +1,26 @@
+#!raku
+
+sub MAIN( Int $top where { $top > 1 } ) {
+ my @solutions;
+ @solutions.push: 1 xx $top;
+
+ my $current-solution = 1 x $top;
+ while ( $current-solution ~~ / 1 ** 2 / ) {
+ $current-solution ~~ s/ 1 ** 2 / 2 /;
+ $current-solution = $current-solution.split( ' ', :skip-empty ).join( '' );
+ @solutions.push: $_ for $current-solution.split( '', :skip-empty ).permutations.unique( as => { .Str.trim } );
+
+
+ }
+
+
+ for @solutions -> @current-solution {
+ say "\nPossible solution:";
+ "%d step%s ".sprintf( $_, $_ > 1 ?? 's' !! '' ).print if $_ > 0 for @current-solution;
+
+ }
+
+ say "";
+
+}
+
diff --git a/challenge-112/mark-anderson/raku/ch-1.raku b/challenge-112/mark-anderson/raku/ch-1.raku
new file mode 100644
index 0000000000..9e7a0b29ef
--- /dev/null
+++ b/challenge-112/mark-anderson/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/usr/bin/env raku
+
+use Test;
+plan 3;
+
+is IO::Spec::Unix.canonpath("/a/"), "/a";
+
+is IO::Spec::Unix.canonpath("/a/b//c/"), "/a/b/c";
+
+is IO::Spec::Unix.canonpath("/a/b/c/../..", :parent), "/a";
diff --git a/challenge-112/mark-anderson/raku/ch-2.raku b/challenge-112/mark-anderson/raku/ch-2.raku
new file mode 100644
index 0000000000..7a4edaffde
--- /dev/null
+++ b/challenge-112/mark-anderson/raku/ch-2.raku
@@ -0,0 +1,137 @@
+#!/usr/bin/env raku
+
+multi MAIN
+{
+ use Test;
+ plan 6;
+
+ is stairs(3).elems, 3;
+
+ is stairs(4).elems, 5;
+
+ is stairs(10).elems, 89;
+
+ is-deeply stairs(3), ((1, 1, 1),
+ (1, 2),
+ (2, 1))>>.Seq;
+
+ is-deeply stairs(4), ((1, 1, 1, 1),
+ (1, 1, 2),
+ (1, 2, 1),
+ (2, 1, 1),
+ (2, 2))>>.Seq;
+
+ is-deeply stairs(10), ((1, 1, 1, 1, 1, 1, 1, 1, 1, 1),
+ (1, 1, 1, 1, 1, 1, 1, 1, 2),
+ (1, 1, 1, 1, 1, 1, 1, 2, 1),
+ (1, 1, 1, 1, 1, 1, 2, 1, 1),
+ (1, 1, 1, 1, 1, 1, 2, 2),
+ (1, 1, 1, 1, 1, 2, 1, 1, 1),
+ (1, 1, 1, 1, 1, 2, 1, 2),
+ (1, 1, 1, 1, 1, 2, 2, 1),
+ (1, 1, 1, 1, 2, 1, 1, 1, 1),
+ (1, 1, 1, 1, 2, 1, 1, 2),
+ (1, 1, 1, 1, 2, 1, 2, 1),
+ (1, 1, 1, 1, 2, 2, 1, 1),
+ (1, 1, 1, 1, 2, 2, 2),
+ (1, 1, 1, 2, 1, 1, 1, 1, 1),
+ (1, 1, 1, 2, 1, 1, 1, 2),
+ (1, 1, 1, 2, 1, 1, 2, 1),
+ (1, 1, 1, 2, 1, 2, 1, 1),
+ (1, 1, 1, 2, 1, 2, 2),
+ (1, 1, 1, 2, 2, 1, 1, 1),
+ (1, 1, 1, 2, 2, 1, 2),
+ (1, 1, 1, 2, 2, 2, 1),
+ (1, 1, 2, 1, 1, 1, 1, 1, 1),
+ (1, 1, 2, 1, 1, 1, 1, 2),
+ (1, 1, 2, 1, 1, 1, 2, 1),
+ (1, 1, 2, 1, 1, 2, 1, 1),
+ (1, 1, 2, 1, 1, 2, 2),
+ (1, 1, 2, 1, 2, 1, 1, 1),
+ (1, 1, 2, 1, 2, 1, 2),
+ (1, 1, 2, 1, 2, 2, 1),
+ (1, 1, 2, 2, 1, 1, 1, 1),
+ (1, 1, 2, 2, 1, 1, 2),
+ (1, 1, 2, 2, 1, 2, 1),
+ (1, 1, 2, 2, 2, 1, 1),
+ (1, 1, 2, 2, 2, 2),
+ (1, 2, 1, 1, 1, 1, 1, 1, 1),
+ (1, 2, 1, 1, 1, 1, 1, 2),
+ (1, 2, 1, 1, 1, 1, 2, 1),
+ (1, 2, 1, 1, 1, 2, 1, 1),
+ (1, 2, 1, 1, 1, 2, 2),
+ (1, 2, 1, 1, 2, 1, 1, 1),
+ (1, 2, 1, 1, 2, 1, 2),
+ (1, 2, 1, 1, 2, 2, 1),
+ (1, 2, 1, 2, 1, 1, 1, 1),
+ (1, 2, 1, 2, 1, 1, 2),
+ (1, 2, 1, 2, 1, 2, 1),
+ (1, 2, 1, 2, 2, 1, 1),
+ (1, 2, 1, 2, 2, 2),
+ (1, 2, 2, 1, 1, 1, 1, 1),
+ (1, 2, 2, 1, 1, 1, 2),
+ (1, 2, 2, 1, 1, 2, 1),
+ (1, 2, 2, 1, 2, 1, 1),
+ (1, 2, 2, 1, 2, 2),
+ (1, 2, 2, 2, 1, 1, 1),
+ (1, 2, 2, 2, 1, 2),
+ (1, 2, 2, 2, 2, 1),
+ (2, 1, 1, 1, 1, 1, 1, 1, 1),
+ (2, 1, 1, 1, 1, 1, 1, 2),
+ (2, 1, 1, 1, 1, 1, 2, 1),
+ (2, 1, 1, 1, 1, 2, 1, 1),
+ (2, 1, 1, 1, 1, 2, 2),
+ (2, 1, 1, 1, 2, 1, 1, 1),
+ (2, 1, 1, 1, 2, 1, 2),
+ (2, 1, 1, 1, 2, 2, 1),
+ (2, 1, 1, 2, 1, 1, 1, 1),
+ (2, 1, 1, 2, 1, 1, 2),
+ (2, 1, 1, 2, 1, 2, 1),
+ (2, 1, 1, 2, 2, 1, 1),
+ (2, 1, 1, 2, 2, 2),
+ (2, 1, 2, 1, 1, 1, 1, 1),
+ (2, 1, 2, 1, 1, 1, 2),
+ (2, 1, 2, 1, 1, 2, 1),
+ (2, 1, 2, 1, 2, 1, 1),
+ (2, 1, 2, 1, 2, 2),
+ (2, 1, 2, 2, 1, 1, 1),
+ (2, 1, 2, 2, 1, 2),
+ (2, 1, 2, 2, 2, 1),
+ (2, 2, 1, 1, 1, 1, 1, 1),
+ (2, 2, 1, 1, 1, 1, 2),
+ (2, 2, 1, 1, 1, 2, 1),
+ (2, 2, 1, 1, 2, 1, 1),
+ (2, 2, 1, 1, 2, 2),
+ (2, 2, 1, 2, 1, 1, 1),
+ (2, 2, 1, 2, 1, 2),
+ (2, 2, 1, 2, 2, 1),
+ (2, 2, 2, 1, 1, 1, 1),
+ (2, 2, 2, 1, 1, 2),
+ (2, 2, 2, 1, 2, 1),
+ (2, 2, 2, 2, 1, 1),
+ (2, 2, 2, 2, 2))>>.Seq;
+}
+
+multi MAIN(UInt $u)
+{
+ my $seq := stairs($u);
+
+ say $seq.elems;
+
+ .say for $seq;
+}
+
+sub stairs(UInt $u)
+{
+ my $head = ('100' x $u).substr(0, $u).parse-base(2);
+ my $tail = ('110' x $u).substr(0, $u).parse-base(2);
+
+ ($head..$tail).map({
+ my $b = .base(2);
+
+ unless $b ~~ /000||111/
+ {
+ $b.comb(/(.)$0?/).map(*.chars)
+ }
+ }).sort
+}
diff --git a/challenge-112/roger-bell-west/perl/ch-1.pl b/challenge-112/roger-bell-west/perl/ch-1.pl
new file mode 100755
index 0000000000..c1bed89bc6
--- /dev/null
+++ b/challenge-112/roger-bell-west/perl/ch-1.pl
@@ -0,0 +1,28 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+is(cp('/a/'),'/a','example 1');
+is(cp('/a/b//c/'),'/a/b/c','example 2');
+is(cp('/a/b/c/../..'),'/a','example 3');
+is(cp('/a/./b'),'/a/b','example 4');
+
+sub cp {
+ my $i=shift;
+ my @p=grep {$_ ne '.'} grep /./,split /\//,$i;
+ my $d=1;
+ while ($d) {
+ $d=0;
+ foreach my $pi (1..$#p) {
+ if ($p[$pi] eq '..') {
+ splice @p,$pi-1,2;
+ $d=1;
+ last;
+ }
+ }
+ }
+ return '/'.join('/',@p);
+}
diff --git a/challenge-112/roger-bell-west/perl/ch-2.pl b/challenge-112/roger-bell-west/perl/ch-2.pl
new file mode 100755
index 0000000000..685630026b
--- /dev/null
+++ b/challenge-112/roger-bell-west/perl/ch-2.pl
@@ -0,0 +1,20 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 3;
+
+is(cs(3),3,'example 1');
+is(cs(4),5,'example 2');
+is(cs(20),10946,'example 3');
+
+sub cs {
+ my $i=shift;
+ my ($a,$b,$c)=(0,1,0);
+ foreach (1..$i) {
+ $c=$a+$b;
+ ($a,$b)=($b,$c);
+ }
+ return $c;
+}
diff --git a/challenge-112/roger-bell-west/python/ch-1.py b/challenge-112/roger-bell-west/python/ch-1.py
new file mode 100755
index 0000000000..cf1ecbd798
--- /dev/null
+++ b/challenge-112/roger-bell-west/python/ch-1.py
@@ -0,0 +1,31 @@
+#! /usr/bin/python3
+
+import unittest
+
+def cp(i):
+ p=[x for x in i.split('/') if x != '' and x != '.']
+ d=True
+ while d:
+ d=False
+ for pi in range(1,len(p)):
+ if p[pi] == '..':
+ p=p[0:pi-2]+p[pi+1:-1]
+ d=True
+ break
+ return '/'+'/'.join(p)
+
+class TestCp(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cp('/a/'),'/a','example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cp('/a/b//c/'),'/a/b/c','example 2')
+
+ def test_ex3(self):
+ self.assertEqual(cp('/a/b/c/../..'),'/a','example 3')
+
+ def test_ex4(self):
+ self.assertEqual(cp('/a/./b'),'/a/b','example 4')
+
+unittest.main()
diff --git a/challenge-112/roger-bell-west/python/ch-2.py b/challenge-112/roger-bell-west/python/ch-2.py
new file mode 100755
index 0000000000..77dcdbca19
--- /dev/null
+++ b/challenge-112/roger-bell-west/python/ch-2.py
@@ -0,0 +1,26 @@
+#! /usr/bin/python3
+
+import unittest
+
+def cs(i):
+ a=0
+ b=1
+ c=0
+ for x in range(i):
+ c=a+b
+ a=b
+ b=c
+ return c
+
+class TestCs(unittest.TestCase):
+
+ def test_ex1(self):
+ self.assertEqual(cs(3),3,'example 1')
+
+ def test_ex2(self):
+ self.assertEqual(cs(4),5,'example 2')
+
+ def test_ex3(self):
+ self.assertEqual(cs(20),10946,'example 3')
+
+unittest.main()
diff --git a/challenge-112/roger-bell-west/raku/ch-1.p6 b/challenge-112/roger-bell-west/raku/ch-1.p6
new file mode 100755
index 0000000000..4b37ee6062
--- /dev/null
+++ b/challenge-112/roger-bell-west/raku/ch-1.p6
@@ -0,0 +1,26 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 4;
+
+is(cp('/a/'),'/a','example 1');
+is(cp('/a/b//c/'),'/a/b/c','example 2');
+is(cp('/a/b/c/../..'),'/a','example 3');
+is(cp('/a/./b'),'/a/b','example 4');
+
+sub cp($i) {
+ my @p=$i.split('/').grep(/./).grep({$_ ne '.'});
+ my $d=1;
+ while ($d) {
+ $d=0;
+ for 1..@p.elems-1 -> $pi {
+ if (@p[$pi] eq '..') {
+ splice @p,$pi-1,2;
+ $d=1;
+ last;
+ }
+ }
+ }
+ return '/' ~ join('/',@p);
+}
diff --git a/challenge-112/roger-bell-west/raku/ch-2.p6 b/challenge-112/roger-bell-west/raku/ch-2.p6
new file mode 100755
index 0000000000..49c6b2c458
--- /dev/null
+++ b/challenge-112/roger-bell-west/raku/ch-2.p6
@@ -0,0 +1,18 @@
+#! /usr/bin/perl6
+
+use Test;
+
+plan 3;
+
+is(cs(3),3,'example 1');
+is(cs(4),5,'example 2');
+is(cs(20),10946,'example 3');
+
+sub cs($i) {
+ my ($a,$b,$c)=(0,1,0);
+ for 1..$i {
+ $c=$a+$b;
+ ($a,$b)=($b,$c);
+ }
+ return $c;
+}
diff --git a/challenge-112/roger-bell-west/ruby/ch-1.rb b/challenge-112/roger-bell-west/ruby/ch-1.rb
new file mode 100755
index 0000000000..e7b8ee5e56
--- /dev/null
+++ b/challenge-112/roger-bell-west/ruby/ch-1.rb
@@ -0,0 +1,39 @@
+#! /usr/bin/ruby
+
+def cp(i)
+ p=i.split('/').find_all {|i| i != '' && i != '.'}
+ d=true
+ while d
+ d=false
+ 1.upto(p.length-1) do |pi|
+ if p[pi] == '..' then
+ p=p[0..pi-2]+p[pi+1..-1]
+ d=true
+ break
+ end
+ end
+ end
+ return '/'+p.join('/')
+end
+
+require 'test/unit'
+
+class TestCp < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal('/a',cp('/a/'))
+ end
+
+ def test_ex2
+ assert_equal('/a/b/c',cp('/a/b//c/'))
+ end
+
+ def test_ex3
+ assert_equal('/a',cp('/a/b/c/../..'))
+ end
+
+ def test_ex4
+ assert_equal('/a/b',cp('/a/./b'))
+ end
+
+end
diff --git a/challenge-112/roger-bell-west/ruby/ch-2.rb b/challenge-112/roger-bell-west/ruby/ch-2.rb
new file mode 100755
index 0000000000..c4659f54ea
--- /dev/null
+++ b/challenge-112/roger-bell-west/ruby/ch-2.rb
@@ -0,0 +1,31 @@
+#! /usr/bin/ruby
+
+def cs(i)
+ a=0
+ b=1
+ c=0
+ 1.upto(i) do
+ c=a+b
+ a=b
+ b=c
+ end
+ return c
+end
+
+require 'test/unit'
+
+class TestCs < Test::Unit::TestCase
+
+ def test_ex1
+ assert_equal(3,cs(3))
+ end
+
+ def test_ex2
+ assert_equal(5,cs(4))
+ end
+
+ def test_ex3
+ assert_equal(10946,cs(20))
+ end
+
+end
diff --git a/challenge-112/roger-bell-west/rust/ch-1.rs b/challenge-112/roger-bell-west/rust/ch-1.rs
new file mode 100755
index 0000000000..2125410393
--- /dev/null
+++ b/challenge-112/roger-bell-west/rust/ch-1.rs
@@ -0,0 +1,40 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(cp("/a/"),"/a");
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(cp("/a/b//c"),"/a/b/c");
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(cp("/a/b/c/../.."),"/a");
+}
+
+#[test]
+fn test_ex4() {
+ assert_eq!(cp("/a/./b"),"/a/b");
+}
+
+fn cp(i: &str) -> String {
+ let mut p=i.split("/").filter(|x| *x != "" && *x != ".").collect::<Vec<_>>();
+ let mut d=true;
+ while d {
+ d=false;
+ for pi in 1..p.len()-1 {
+ if p[pi] == ".." {
+ p=[&p[0..pi-2],&p[pi+1..p.len()-1]].concat();
+ d=true;
+ break;
+ }
+ }
+ }
+ let mut r="/".to_string();
+ r.push_str(&p.join("/"));
+ return r;
+}
diff --git a/challenge-112/roger-bell-west/rust/ch-2.rs b/challenge-112/roger-bell-west/rust/ch-2.rs
new file mode 100755
index 0000000000..e0a8f27aa1
--- /dev/null
+++ b/challenge-112/roger-bell-west/rust/ch-2.rs
@@ -0,0 +1,29 @@
+#! /bin/sh
+//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x; rm -f ${0}x ; exit
+
+#[test]
+fn test_ex1() {
+ assert_eq!(cs(3),3);
+}
+
+#[test]
+fn test_ex2() {
+ assert_eq!(cs(4),5);
+}
+
+#[test]
+fn test_ex3() {
+ assert_eq!(cs(20),10946);
+}
+
+fn cs(i: u64) -> u64 {
+ let mut a: u64=0;
+ let mut b: u64=1;
+ let mut c: u64=0;
+ for _x in 0..i {
+ c=a+b;
+ a=b;
+ b=c;
+ }
+ return c;
+}
diff --git a/stats/pwc-challenge-018.json b/stats/pwc-challenge-018.json
index 673f315fe7..b4792f5c1c 100644
--- a/stats/pwc-challenge-018.json
+++ b/stats/pwc-challenge-018.json
@@ -1,67 +1,52 @@
{
- "legend" : {
- "enabled" : 0
- },
"tooltip" : {
- "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>",
"followPointer" : 1,
- "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>"
- },
- "chart" : {
- "type" : "column"
+ "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>",
+ "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>"
},
- "plotOptions" : {
- "series" : {
- "dataLabels" : {
- "enabled" : 1,
- "format" : "{point.y}"
- },
- "borderWidth" : 0
- }
- },
- "subtitle" : {
- "text" : "[Champions: 31] Last updated at 2021-01-17 01:55:13 GMT"
+ "legend" : {
+ "enabled" : 0
},
- "xAxis" : {
- "type" : "category"
+ "title" : {
+ "text" : "Perl Weekly Challenge - 018"
},
"series" : [
{
"data" : [
{
- "y" : 3,
+ "drilldown" : "Adam Russell",
"name" : "Adam Russell",
- "drilldown" : "Adam Russell"
+ "y" : 3
},
{