diff options
| author | Doomtrain14 <yet.ebreo@gmail.com> | 2019-08-25 13:28:48 +0800 |
|---|---|---|
| committer | Doomtrain14 <yet.ebreo@gmail.com> | 2019-08-25 13:28:48 +0800 |
| commit | 2f72acabd6c7ad18143b3b5284a8190a9449cdd2 (patch) | |
| tree | 7fa206f0c3e757560aca091f9a4bbbb043464c09 | |
| parent | ef987715e48bd087bba05e1f356be5f75e0c35a2 (diff) | |
| parent | 90c947e84d8ed64f828d683d39423ab775ae8eee (diff) | |
| download | perlweeklychallenge-club-2f72acabd6c7ad18143b3b5284a8190a9449cdd2.tar.gz perlweeklychallenge-club-2f72acabd6c7ad18143b3b5284a8190a9449cdd2.tar.bz2 perlweeklychallenge-club-2f72acabd6c7ad18143b3b5284a8190a9449cdd2.zip | |
Merge branch 'master' of https://github.com/manwar/perlweeklychallenge-club
45 files changed, 4729 insertions, 4513 deletions
diff --git a/challenge-018/laurent-rosenfeld/blog2.txt b/challenge-018/laurent-rosenfeld/blog2.txt new file mode 100644 index 0000000000..166c74cd83 --- /dev/null +++ b/challenge-018/laurent-rosenfeld/blog2.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/Priority-queues.md diff --git a/challenge-018/laurent-rosenfeld/blog3.txt b/challenge-018/laurent-rosenfeld/blog3.txt new file mode 100644 index 0000000000..df5e7bd20e --- /dev/null +++ b/challenge-018/laurent-rosenfeld/blog3.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/Longest-substring.md diff --git a/challenge-019/laurent-rosenfeld/blog1.txt b/challenge-019/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..7273796061 --- /dev/null +++ b/challenge-019/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/wrapping-lines.md diff --git a/challenge-019/laurent-rosenfeld/blog2.txt b/challenge-019/laurent-rosenfeld/blog2.txt new file mode 100644 index 0000000000..ecf66fccdd --- /dev/null +++ b/challenge-019/laurent-rosenfeld/blog2.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/Five-weekends-in-a-month.md diff --git a/challenge-021/laurent-rosenfeld/blog1.txt b/challenge-021/laurent-rosenfeld/blog1.txt new file mode 100644 index 0000000000..b086296e3a --- /dev/null +++ b/challenge-021/laurent-rosenfeld/blog1.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/URL-normalization.md diff --git a/challenge-021/laurent-rosenfeld/blog2.txt b/challenge-021/laurent-rosenfeld/blog2.txt new file mode 100644 index 0000000000..2bf3593797 --- /dev/null +++ b/challenge-021/laurent-rosenfeld/blog2.txt @@ -0,0 +1 @@ +https://github.com/LaurentRosenfeld/Perl-6-Miscellaneous/blob/master/Challenges-in-Perl6/Euler-number.md diff --git a/challenge-022/mark-senn/blog.txt b/challenge-022/mark-senn/blog.txt new file mode 100644 index 0000000000..4f5026aa6c --- /dev/null +++ b/challenge-022/mark-senn/blog.txt @@ -0,0 +1 @@ +https://engineering.purdue.edu/~mark/pwc-022-1.pdf diff --git a/challenge-022/mark-senn/perl6/ch-1.p6 b/challenge-022/mark-senn/perl6/ch-1.p6 new file mode 100644 index 0000000000..b6caeb1a99 --- /dev/null +++ b/challenge-022/mark-senn/perl6/ch-1.p6 @@ -0,0 +1,31 @@ +# +# Perl Weekly Challenge - 022 +# Task #1 +# +# See +# engineering.purdue.edu/~mark/pwc -022 -1. pdf +# for more information. + +# Run using Perl v6.d. +use v6.d; + +my$d = 6; # sexy primes differ by 6 +my$n = 10; # print the first$n sexy prime pairs +my$p = 0; # how many sexy prime pairs have been printed +my$size = 2; # size of the circular buffer + +# Make a$size element circular buffer. +# Make each element the illegal value of 2 -$d - 1 (= -5). +# The circular buffer will get seeded with the correct values later. +# The first sexy prime pair will be found at (5 ,11). +my @cb[$size] = (2-$d -1) xx *; + +my$i = 0; # Current index into cb +for ((2.. Inf).grep ({.is -prime })) { # For each prime number ... + if ($_ -$d == @cb.any) { # is it part of a sexy prime pair? + "({$_ -$d},$_)". say; # print the sexy prime pair + (++$p ==$n) and last; # have we printed$n sexy prime pairs? + } + @cb[$i++ %$size] =$_; # put the new prime in the circlar buffer + # say "cb = {@cb}"; # (for testing) +} diff --git a/challenge-022/roger-bell-west/blog.txt b/challenge-022/roger-bell-west/blog.txt new file mode 100644 index 0000000000..5ffe885bb4 --- /dev/null +++ b/challenge-022/roger-bell-west/blog.txt @@ -0,0 +1 @@ +https://blog.firedrake.org/archive/2019/08/Perl_Weekly_Challenge_22.html diff --git a/challenge-022/ruben-westerberg/README b/challenge-022/ruben-westerberg/README index 1f319161be..26a2690833 100644 --- a/challenge-022/ruben-westerberg/README +++ b/challenge-022/ruben-westerberg/README @@ -2,13 +2,9 @@ Solution by Ruben Westerberg ch-1.pl and ch-1.p6 === -Run with a single argument. Argument is the number of terms to add in calculating Eulers number. If no argument is given, a default of 10 terms are used. +Run the program to calculate the first ten sexy prime pairs ch-2.pl and ch-2.p6 === -Run with a single argument. Argument is a URI which is normalized (no semantic changes). If no argument is given a test URI is used. -- Normalizes scheme to lower case -- Normalize % codes to upper case -- decode unreserved % codes if present -- encode any characters outside of reserved or unreserved codes. +Run the program with a command line argument to demonstrate the LZW encoding. With no argument, a demonstration string is used diff --git a/challenge-022/ruben-westerberg/perl5/ch-1.pl b/challenge-022/ruben-westerberg/perl5/ch-1.pl new file mode 100755 index 0000000000..8c54633ad7 --- /dev/null +++ b/challenge-022/ruben-westerberg/perl5/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use v5.26; + +#Find the first 10 sexy primes + +my $i=1; +my $count=10; +my @primes; +while ($count) { + if (isPrime($i)) { + @primes=grep { $i-$_ <=6} @primes; + my @match=grep {$i-6 == $_} @primes; + if (@match) { + printf "Sexy Pair: %d,%d\n", $match[0], $i; + $count--; + } + push @primes, $i; + } + $i++; +} + +sub isPrime { + my $t=shift; + my $sum=0; + for (1..(int $t/2)) { + $sum++ if $t % $_ == 0; + last if $sum >1; + } + $sum==1; +} diff --git a/challenge-022/ruben-westerberg/perl5/ch-2.pl b/challenge-022/ruben-westerberg/perl5/ch-2.pl new file mode 100755 index 0000000000..98895fd8e7 --- /dev/null +++ b/challenge-022/ruben-westerberg/perl5/ch-2.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util qw<uniq first>; +use v5.26; + +# implement LZW +my @input=split "", $ARGV[0]//"TOBEORNOTTOBEORTOBEORNOT"; +my @decoded; +my @encoded; +my @symbols; + +print "Input: ",join("",@input),"\n"; + +encode(\@symbols, \@input ,\@encoded); + +print "Encoded: ",join(",",@encoded),"\n"; + +decode(\@symbols,\@encoded,\@decoded); + +print "Decoded: ",join("",@decoded),"\n"; + + + +sub encode { + my ($dict,$in, $out)=@_; + @$dict= uniq @$in;# ((0..9),('A'..'Z'),('a'..'z')); + push @$in, undef; + for (@$in) { + state $symbol=""; + my $next=$_;#shift; + $symbol.=$next if defined $next; + state $prev=""; + my $s=first {$symbol eq $_} @$dict; + unless ( $s and $next) { + push @$dict, $symbol; + push @$out, first {$prev eq $$dict[$_]} 0..@$dict-1; + $symbol=substr $symbol, -1; + } + $prev=$symbol; + } +} + + +sub decode { + my ($dict,$in,$out)=@_; + for (@$in) { + push @$out, @$dict[$_]; + } +} diff --git a/challenge-022/ruben-westerberg/perl6/ch-1.p6 b/challenge-022/ruben-westerberg/perl6/ch-1.p6 new file mode 100755 index 0000000000..66552158d6 --- /dev/null +++ b/challenge-022/ruben-westerberg/perl6/ch-1.p6 @@ -0,0 +1,14 @@ +#!/usr/bin/env perl6 + +((1..*).grep: *.is-prime).map(->$p { + state @search; + state $count =10; + @search=@search.grep({$p-$_ <=6}); + my @match=@search.grep({$p-6 == $_}); + if @match { + put "Sexy Pair: @match[0],$p"; + last unless --$count; + } + @search.push: $p; +}); + diff --git a/challenge-022/ruben-westerberg/perl6/ch-2.p6 b/challenge-022/ruben-westerberg/perl6/ch-2.p6 new file mode 100755 index 0000000000..23c5e67daa --- /dev/null +++ b/challenge-022/ruben-westerberg/perl6/ch-2.p6 @@ -0,0 +1,43 @@ +#!/usr/bin/env perl6 + +# implement LZW +my @input=comb "", @*ARGS[0]//"TOBEORNOTTOBEORTOBEORNOT"; +my @decoded; +my @encoded; +my @symbols; + +print "Input: ",join("",@input),"\n"; + +encode(@symbols, @input ,@encoded); + +print "Encoded: ",join(",",@encoded),"\n"; + +decode(@symbols,@encoded,@decoded); + +print "Decoded: ",join("",@decoded),"\n"; + + +sub encode (@dict, @in, @out) { + @dict= @in.unique; #Create initial dictionary + push @in, Any; #Add end marker to input + for @in { + state $symbol=""; + my $next=$_; + $symbol~=$next if $next.defined; + state $prev=""; + my $s=first {$symbol eq $_}, @dict; #Search for existing + unless $s.defined and $next.defined { + push @dict, $symbol; + push @out, @dict.first: {$prev eq $_ },:k; + $symbol=substr $symbol, *-1; + } + $prev=$symbol; + } +} + + +sub decode(@dict, @in, @out) { + for @in { + push @out, @dict[$_]; + } +} diff --git a/stats/pwc-challenge-001.json b/stats/pwc-challenge-001.json index 7a5fd62fd6..7840341960 100644 --- a/stats/pwc-challenge-001.json +++ b/stats/pwc-challenge-001.json @@ -1,286 +1,17 @@ { - "series" : [ - { - "colorByPoint" : 1, - "name" : "Perl Weekly Challenge - 001", - "data" : [ - { - "name" : "Adam Russell", - "y" : 3, - "drilldown" : "Adam Russell" - }, - { - "name" : "Ailbhe Tweedie", - "drilldown" : "Ailbhe Tweedie", - "y" : 1 - }, - { - "y" : 2, - "drilldown" : "Alex Daniel", - "name" : "Alex Daniel" - }, - { - "drilldown" : "Andrezgz", - "y" : 2, - "name" : "Andrezgz" - }, - { - "name" : "Antonio Gamiz", - "drilldown" : "Antonio Gamiz", - "y" : 2 - }, - { - "drilldown" : "Arpad Toth", - "y" : 2, - "name" : "Arpad Toth" - }, - { - "name" : "Athanasius", - "y" : 2, - "drilldown" : "Athanasius" - }, - { - "y" : 2, - "drilldown" : "Bob Kleemann", - "name" : "Bob Kleemann" - }, - { - "name" : "Daniel Mantovani", - "drilldown" : "Daniel Mantovani", - "y" : 1 - }, - { - "name" : "Dave Cross", - "y" : 3, - "drilldown" : "Dave Cross" - }, - { - "y" : 2, - "drilldown" : "Dave Jacoby", - "name" : "Dave Jacoby" - }, - { - "name" : "David Kayal", - "y" : 2, - "drilldown" : "David Kayal" - }, - { - "y" : 2, - "drilldown" : "Doug Schrag", - "name" : "Doug Schrag" - }, - { - "name" : "Dr James A. Smith", - "y" : 4, - "drilldown" : "Dr James A. Smith" - }, - { - "name" : "Duncan C. White", - "y" : 2, - "drilldown" : "Duncan C. White" - }, - { - "name" : "Eddy HS", - "y" : 2, - "drilldown" : "Eddy HS" - }, - { - "name" : "Finley", - "drilldown" : "Finley", - "y" : 2 - }, - { - "y" : 1, - "drilldown" : "Fred Zinn", - "name" : "Fred Zinn" - }, - { - "name" : "Freddie B", - "y" : 2, - "drilldown" : "Freddie B" - }, - { - "drilldown" : "Gustavo Chaves", - "y" : 1, - "name" : "Gustavo Chaves" - }, - { - "name" : "JJ Merelo", - "drilldown" : "JJ Merelo", - "y" : 2 - }, - { - "y" : 4, - "drilldown" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas" - }, - { - "y" : 2, - "drilldown" : "Jeff", - "name" : "Jeff" - }, - { - "drilldown" : "Jeremy Carman", - "y" : 2, - "name" : "Jeremy Carman" - }, - { - "y" : 1, - "drilldown" : "Jim Bacon", - "name" : "Jim Bacon" - }, - { - "y" : 5, - "drilldown" : "Jo Christian Oterhals", - "name" : "Jo Christian Oterhals" - }, - { - "y" : 4, - "drilldown" : "Joelle Maslak", - "name" : "Joelle Maslak" - }, - { - "name" : "John Barrett", - "y" : 1, - "drilldown" : "John Barrett" - }, - { - "y" : 2, - "drilldown" : "Juan Caballero", - "name" : "Juan Caballero" - }, - { - "drilldown" : "Khalid", - "y" : 2, - "name" : "Khalid" - }, - { - "name" : "Kian-Meng Ang", - "y" : 3, - "drilldown" : "Kian-Meng Ang" - }, - { - "y" : 2, - "drilldown" : "Kivanc Yazan", - "name" : "Kivanc Yazan" - }, - { - "name" : "Lars Balker", - "drilldown" : "Lars Balker", - "y" : 4 - }, - { - "y" : 4, - "drilldown" : "Laurent Rosenfeld", - "name" : "Laurent Rosenfeld" - }, - { - "drilldown" : "Mark Senn", - "y" : 2, - "name" : "Mark Senn" - }, - { - "y" : 2, - "drilldown" : "Martin Mugeni", - "name" : "Martin Mugeni" - }, - { - "name" : "Neil Bowers", - "drilldown" : "Neil Bowers", - "y" : 1 - }, - { - "y" : 4, - "drilldown" : "Nick Logan", - "name" : "Nick Logan" - }, - { - "name" : "Oleksii Tsvietnov", - "drilldown" : "Oleksii Tsvietnov", - "y" : 2 - }, - { - "y" : 2, - "drilldown" : "Ozzy", - "name" : "Ozzy" - }, - { - "y" : 2, - "drilldown" : "Pavel Jurca", - "name" : "Pavel Jurca" - }, - { - "y" : 2, - "drilldown" : "Pete Houston", - "name" : "Pete Houston" - }, - { - "name" : "Philippe Bruhat", - "drilldown" : "Philippe Bruhat", - "y" : 3 - }, - { - "name" : "Prajith P", - "y" : 1, - "drilldown" : "Prajith P" - }, - { - "name" : "Sean Meininger", - "y" : 2, - "drilldown" : "Sean Meininger" - }, - { - "name" : "Simon Proctor", - "drilldown" : "Simon Proctor", - "y" : 6 - }, - { - "name" : "Simon Reinhardt", - "drilldown" : "Simon Reinhardt", - "y" : 2 - }, - { - "y" : 4, - "drilldown" : "Steve Rogerson", - "name" : "Steve Rogerson" - }, - { - "drilldown" : "Steven Wilson", - "y" : 2, - "name" : "Steven Wilson" - }, - { - "y" : 1, - "drilldown" : "Tiago Stock", - "name" : "Tiago Stock" - }, - { - "y" : 2, - "drilldown" : "Tore Andersson", - "name" : "Tore Andersson" - }, - { - "drilldown" : "Veesh Goldman", - "y" : 1, - "name" : "Veesh Goldman" - }, - { - "name" : "William Gilmore", - "y" : 1, - "drilldown" : "William Gilmore" - } - ] + "plotOptions" : { + "series" : { + "borderWidth" : 0, + "dataLabels" : { + "enabled" : 1, + "format" : "{point.y}" + } } - ], - "legend" : { - "enabled" : 0 - }, - "xAxis" : { - "type" : "category" }, "drilldown" : { "series" : [ { + "name" : "Adam Russell", "data" : [ [ "Perl 5", @@ -291,91 +22,90 @@ 1 ] ], - "name" : "Adam Russell", "id" : "Adam Russell" }, { "id" : "Ailbhe Tweedie", + "name" : "Ailbhe Tweedie", "data" : [ [ "Perl 5", 1 ] - ], - "name" : "Ailbhe Tweedie" + ] }, { - "name" : "Alex Daniel", + "id" : "Alex Daniel", "data" : [ [ "Perl 6", 2 ] ], - "id" : "Alex Daniel" + "name" : "Alex Daniel" }, { - "id" : "Andrezgz", "name" : "Andrezgz", "data" : [ [ "Perl 5", 2 ] - ] + ], + "id" : "Andrezgz" }, { - "id" : "Antonio Gamiz", "name" : "Antonio Gamiz", "data" : [ [ "Perl 6", 2 ] - ] + ], + "id" : "Antonio Gamiz" }, { - "id" : "Arpad Toth", + "name" : "Arpad Toth", "data" : [ [ "Perl 5", 2 ] ], - "name" : "Arpad Toth" + "id" : "Arpad Toth" }, { "id" : "Athanasius", - "name" : "Athanasius", "data" : [ [ "Perl 5", 2 ] - ] + ], + "name" : "Athanasius" }, { + "id" : "Bob Kleemann", "data" : [ [ "Perl 5", 2 ] ], - "name" : "Bob Kleemann", - "id" : "Bob Kleemann" + "name" : "Bob Kleemann" }, { + "id" : "Daniel Mantovani", + "name" : "Daniel Mantovani", "data" : [ [ "Perl 5", 1 ] - ], - "name" : "Daniel Mantovani", - "id" : "Daniel Mantovani" + ] }, { - "name" : "Dave Cross", + "id" : "Dave Cross", "data" : [ [ "Perl 5", @@ -386,11 +116,10 @@ 1 ] ], - "id" : "Dave Cross" + "name" : "Dave Cross" }, { "id" : "Dave Jacoby", - "name" : "Dave Jacoby", "data" : [ [ "Perl 5", @@ -400,29 +129,31 @@ "Blog", 1 ] - ] + ], + "name" : "Dave Jacoby" }, { - "id" : "David Kayal", - "name" : "David Kayal", "data" : [ [ "Perl 5", 2 ] - ] + ], + "name" : "David Kayal", + "id" : "David Kayal" }, { - "name" : "Doug Schrag", + "id" : "Doug Schrag", "data" : [ [ "Perl 6", 2 ] ], - "id" : "Doug Schrag" + "name" : "Doug Schrag" }, { + "id" : "Dr James A. Smith", "data" : [ [ "Perl 5", @@ -433,71 +164,69 @@ 2 |
