diff options
| author | Francis Whittle <FJ.Whittle@gmail.com> | 2019-04-13 13:33:22 +1000 |
|---|---|---|
| committer | Francis Whittle <FJ.Whittle@gmail.com> | 2019-04-13 13:34:10 +1000 |
| commit | 081b96b81df4e12870d90d905db8aaf7f0bbaed8 (patch) | |
| tree | 80605e40e81209c944869970477b909578edabb3 | |
| parent | 07e929354cbb95a6bcb009f75ac3a07a7669e4b8 (diff) | |
| parent | 8b880c7d6af0196945a1fbc84dd5f5f56cd0a683 (diff) | |
| download | perlweeklychallenge-club-081b96b81df4e12870d90d905db8aaf7f0bbaed8.tar.gz perlweeklychallenge-club-081b96b81df4e12870d90d905db8aaf7f0bbaed8.tar.bz2 perlweeklychallenge-club-081b96b81df4e12870d90d905db8aaf7f0bbaed8.zip | |
Merge remote-tracking branch 'origin/master'
26 files changed, 855 insertions, 292 deletions
diff --git a/challenge-001/nick-logan/perl5/ch-1.pl b/challenge-001/nick-logan/perl5/ch-1.pl index c35822d44b..e20ce33987 100644 --- a/challenge-001/nick-logan/perl5/ch-1.pl +++ b/challenge-001/nick-logan/perl5/ch-1.pl @@ -1 +1,3 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + print((($_ eq "e") and uc($_) or $_)) for split("", "Perl Weekly Challenge") diff --git a/challenge-001/nick-logan/perl5/ch-2.pl b/challenge-001/nick-logan/perl5/ch-2.pl index cb8a9074af..00372d5c38 100644 --- a/challenge-001/nick-logan/perl5/ch-2.pl +++ b/challenge-001/nick-logan/perl5/ch-2.pl @@ -1,3 +1,3 @@ -print((join( "", (!($_ % 3) and "Fizz" or ""), (!($_ % 5) and "Buzz" or "") ) or $_), "\n") for 1..20; - +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both +print((join( "", (!($_ % 3) and "Fizz" or ""), (!($_ % 5) and "Buzz" or "") ) or $_), "\n") for 1..20; diff --git a/challenge-001/nick-logan/perl6/ch-1.p6 b/challenge-001/nick-logan/perl6/ch-1.p6 index c35822d44b..e20ce33987 100644 --- a/challenge-001/nick-logan/perl6/ch-1.p6 +++ b/challenge-001/nick-logan/perl6/ch-1.p6 @@ -1 +1,3 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + print((($_ eq "e") and uc($_) or $_)) for split("", "Perl Weekly Challenge") diff --git a/challenge-001/nick-logan/perl6/ch-2.p6 b/challenge-001/nick-logan/perl6/ch-2.p6 index cb8a9074af..00372d5c38 100644 --- a/challenge-001/nick-logan/perl6/ch-2.p6 +++ b/challenge-001/nick-logan/perl6/ch-2.p6 @@ -1,3 +1,3 @@ -print((join( "", (!($_ % 3) and "Fizz" or ""), (!($_ % 5) and "Buzz" or "") ) or $_), "\n") for 1..20; - +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both +print((join( "", (!($_ % 3) and "Fizz" or ""), (!($_ % 5) and "Buzz" or "") ) or $_), "\n") for 1..20; diff --git a/challenge-002/nick-logan/perl5/ch-1.pl b/challenge-002/nick-logan/perl5/ch-1.pl index f7787b8a04..ffbf7bc003 100644 --- a/challenge-002/nick-logan/perl5/ch-1.pl +++ b/challenge-002/nick-logan/perl5/ch-1.pl @@ -1 +1,3 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + my @ARGV = do { sub eval($_) { &EVAL($_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; print("$_\n") for map &{ sub ($_) { /^0(0|1|2|3|4|5|6|7|8|9)+/ and (0+$_) or $_ } }.(), @ARGV; diff --git a/challenge-002/nick-logan/perl5/ch-2.pl b/challenge-002/nick-logan/perl5/ch-2.pl index f6d6226cda..95628189ed 100644 --- a/challenge-002/nick-logan/perl5/ch-2.pl +++ b/challenge-002/nick-logan/perl5/ch-2.pl @@ -1,3 +1,5 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; my ($state, $result, $dict, $base35) = (1, "", {}, @ARGV[0]); $dict{$_} = $_ for "1".."9"; diff --git a/challenge-002/nick-logan/perl6/ch-1.p6 b/challenge-002/nick-logan/perl6/ch-1.p6 index f7787b8a04..ffbf7bc003 100644 --- a/challenge-002/nick-logan/perl6/ch-1.p6 +++ b/challenge-002/nick-logan/perl6/ch-1.p6 @@ -1 +1,3 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + my @ARGV = do { sub eval($_) { &EVAL($_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; print("$_\n") for map &{ sub ($_) { /^0(0|1|2|3|4|5|6|7|8|9)+/ and (0+$_) or $_ } }.(), @ARGV; diff --git a/challenge-002/nick-logan/perl6/ch-2.p6 b/challenge-002/nick-logan/perl6/ch-2.p6 index f6d6226cda..95628189ed 100644 --- a/challenge-002/nick-logan/perl6/ch-2.p6 +++ b/challenge-002/nick-logan/perl6/ch-2.p6 @@ -1,3 +1,5 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; my ($state, $result, $dict, $base35) = (1, "", {}, @ARGV[0]); $dict{$_} = $_ for "1".."9"; diff --git a/challenge-002/nick-logan/perl6/to-base35.p6 b/challenge-002/nick-logan/perl6/to-base35.p6 index 683acda914..e4f7e98a95 100644 --- a/challenge-002/nick-logan/perl6/to-base35.p6 +++ b/challenge-002/nick-logan/perl6/to-base35.p6 @@ -1,3 +1,5 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + # bin/to-base35 sub to_int($_) { my @i = split(/"."/, $_[0]); @i[0] }; my @ARGV = do { sub eval { chomp &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; @@ -5,7 +7,7 @@ my ($result, $dict, $base10) = ("", {}, @ARGV[0]); $dict{$_} = $_ for "1".."9"; $dict{ord($_) - 55} = $_ for "A".."Y"; while ($base10 > 0) { - $result = join("", $dict{to_int($base10 % 35)}, $result); - $base10 = to_int($base10 / 35); + $result = join("", $dict{to_int($base10 % 35)}, $result); + $base10 = to_int($base10 / 35); } print("$result\n"); diff --git a/challenge-003/andrezgz/perl5/ch-1.pl b/challenge-003/andrezgz/perl5/ch-1.pl new file mode 100644 index 0000000000..cec1731d72 --- /dev/null +++ b/challenge-003/andrezgz/perl5/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-003/ +# Challenge #1 +# Create a script to generate 5-smooth numbers, whose prime divisors are less or equal to 5. +# They are also called Hamming/Regular/Ugly numbers. +# For more information, please check this wikipedia. https://en.wikipedia.org/wiki/Regular_number + +use strict; + +my $last = shift || 20; + +foreach my $n ( 1 .. $last ) { + my $r = $n; + for (2,3,5) { $r /= $_ until ($r % $_) } + print $n.$/ if ($r == 1); +} diff --git a/challenge-003/andrezgz/perl5/ch-2.pl b/challenge-003/andrezgz/perl5/ch-2.pl new file mode 100644 index 0000000000..3d9d8e208a --- /dev/null +++ b/challenge-003/andrezgz/perl5/ch-2.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +# https://perlweeklychallenge.org/blog/perl-weekly-challenge-003/ +# Challenge #2 +# Create a script that generates Pascal Triangle. Accept number of rows from the command line. +# The Pascal Triangle should have at least 3 rows. +# For more information about Pascal Triangle, check this wikipedia page. https://en.wikipedia.org/wiki/Pascal%27s_triangle + +use strict; +use warnings; + +my $rows = $ARGV[0] || 0; + +if ($rows < 3) { + print "The Pascal Triangle should have at least 3 rows\n"; + $rows = 3; +} + +my @row = (1); + +while ($rows) { + print join(' ',@row) .$/; + $rows--; + @row = map {$row[$_] += $row[$_+1]} 0..@row-2; + unshift @row, 1; + push @row, 1; +} diff --git a/challenge-003/daniel-mantovani/perl5/ch-1.pl b/challenge-003/daniel-mantovani/perl5/ch-1.pl new file mode 100644 index 0000000000..fa23ce0075 --- /dev/null +++ b/challenge-003/daniel-mantovani/perl5/ch-1.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl +use strict; +use warnings; +use v5.10; + +my $q = $ARGV[0]; + +die + "Usage: perl $0 <n>\n\nwhere <n> is the (integer) quantity of hamming numbers you ask" + unless $q && $q =~ /^\d+$/; + +my @primes = (2, 3, 5); + +# for each prime, we will define one vector (array), whith just one element [1] +# note that [1] will be first hamming code inside each array! + +my %vec; +$vec{$_} = [1] for @primes; + +for my $i (1 .. $q) { + +# just look for the min value from the head of v2, v3 or v5 +# (without using List::Util, as the challenge encourages no to use external modules) + my $h; + map { $h = $vec{$_}[0] unless $h && $h < $vec{$_}[0] } @primes; + + # and we just got the next hamming number! + say "$i\t", $h; + + for my $f (@primes) { # now for every prime factor + # remove this value on each vector where it is present + shift @{$vec{$f}} if $vec{$f}[0] == $h; + + # and finally calculate and insert new values to each vector + # note that new pushed value is higer than any previous value in each vector + push @{$vec{$f}}, $h * $f; + } +} diff --git a/challenge-003/duncan-c-white/README b/challenge-003/duncan-c-white/README index 81f31dc7c0..d6a6cb2f04 100644 --- a/challenge-003/duncan-c-white/README +++ b/challenge-003/duncan-c-white/README @@ -1 +1,8 @@ -Solution by Duncan C. White +I have investigated Challenge 1 (the Regular numbers) reasonably thoroughly, +building and comparing 4 iterative solutions to generate them. I also +investigated a Lazy List version, storing the tail of the list as a promise - +a function to call when you wanted the next head item, and the returned tail +is another promise - to generate the next item later when needed. However, +I couldn't get that to work so abandoned it:-) + +Challenge 2 (Pascal's Triangle) by contrast is pretty basic and simple-minded. diff --git a/challenge-003/duncan-c-white/perl5/ch-1.pl b/challenge-003/duncan-c-white/perl5/ch-1.pl new file mode 100755 index 0000000000..3e6cf63ed4 --- /dev/null +++ b/challenge-003/duncan-c-white/perl5/ch-1.pl @@ -0,0 +1,220 @@ +#!/usr/bin/perl +# +# iterative generation of the first N regular numbers +# (numbers of the form 2^i.3^j.5^k) +# in ascending order, using 4 different algorithms. +# +# This program takes two optional arguments: +# ch-1-pl [benchmark [firstN]] +# where benchmark defaults to 0, and firstN to 1000. +# - If benchmark is 0, we run each algorithm in turn +# and minimally checks that each algorithm generates +# the same list. +# - If benchmark is any non-zero value (+ or -), each +# algorithm is Benchmarked with the $benchmark value +# as Benchmark::timethese's first parameter. Thus, +# a +ve value means "benchmark this many iterations", +# while a -ve value means "benchmark for abs(this) seconds". +# +# So, for example: +# ./ch-1.pl 0 +# runs all 4 algorithms, telling you whether each result is the same.. +# but: +# ./ch-1.pl -60 +# runs all 4 algorithms repeatedly under Benchmark, and reports: +# Benchmark: running v1, v2, v3, v4 for at least 60 CPU seconds... +# v1: 69 wallclock secs (68.38 usr + 0.00 sys = 68.38 CPU) @ 0.06/s (n=4) +# v2: 64 wallclock secs (63.17 usr + 0.00 sys = 63.17 CPU) @ 26.29/s (n=1661) +# v3: 62 wallclock secs (62.54 usr + 0.00 sys = 62.54 CPU) @ 45.24/s (n=2829) +# v4: 63 wallclock secs (63.38 usr + 0.00 sys = 63.38 CPU) @ 127.90/s (n=8106) + +use strict; +use warnings; + +use Benchmark qw(:all) ; + +# +# my @result = firstn_regnos_v1( $n ); +# Generate the first N regular numbers via basic GENERATE AND TEST: +# generate every integer, then check "is it 2^i.3^j.5^k for any i,j,k"? +# Returns a list of the first N regular numbers. +# +sub firstn_regnos_v1 +{ + my( $n ) = @_; + my @result = (1); + for( my $x=2; @result<$n; $x++ ) + { + my $y=$x; + $y/=5 while $y%5==0; + $y/=3 while $y%3==0; + $y/=2 while $y%2==0; + push @result, $x if $y==1; + } + return @result; +} + + +# +# my @result = firstn_regnos_v2( $n ); +# Generate the first N regular numbers via a todo set +# of higher 2^i.3^j.5^k values that we haven't yet +# checked, and sorting the todo list to pick the smallest +# every time. Returns a list of the first N regular numbers. +# +sub firstn_regnos_v2 +{ + my( $n ) = @_; + my @result = (1); + my %todo = map { $_ => 1 } qw(2 3 5); + for( my $i=1; $i<$n; $i++ ) + { + my @todo = sort { $a <=> $b } keys %todo; + my $next = shift @todo; + push @result, $next; + # update the todo set: next is done, so remove it + delete $todo{$next}; + # update the todo set: add 2*next, 3*nect and 5*next + $todo{2*$next}++; + $todo{3*$next}++; + $todo{5*$next}++; + } + return @result; +} + + +# +# my @result = firstn_regnos_v3( $n ); +# Generate the first N regular numbers via a todo set +# of higher 2^i.3^j.5^k values that we haven't yet +# checked. It's the same as _v2 EXCEPT that we pick the +# smallest element in a different and more efficient way - +# by searching linearly through the todo set - instead of +# forming a list and sorting it, every time. +# Returns a list of the first N regular numbers. +# +sub firstn_regnos_v3 +{ + my( $n ) = @_; + my @result = (1); + my %v = map { $_ => 1 } qw(2 3 5); + for( my $i=1; $i<$n; $i++ ) + { + my $min = each %v; + while( my $v = each %v ) + { + $min = $v if $min>$v; + } + my $next = $min; + push @result, $next; + delete $v{$next}; + $v{2*$next}++; + $v{3*$next}++; + $v{5*$next}++; + } + return @result; +} + + +# +# my @result = firstn_regnos_v4( $firstn ); +# Generate the first $firstn regular numbers via a more +# constrained "todo set" that never has both than +# one term i-j-X or i-X-k or X-j-k in. This is faster +# and uses less memory. +# Returns a list of the first $firstn regular numbers. +# +sub firstn_regnos_v4 +{ + my( $firstn ) = @_; + my @result = (); + my @next = ( [ 1,0,0,0 ] ); # list of N-i-j-k 4-tuples + my %haveij; # distinct "i-j" pairs in @next + my %haveik; # distinct "i-k" pairs + my %havejk; # distinct "j-k" pairs + for( my $a=1; $a<=$firstn; $a++ ) + { + my $tuple = shift @next; + my( $n, $i, $j, $k ) = @$tuple; + #print "debug: result n=$n, i=$i, j=$j, k=$k\n"; + push @result, $n; + # remove i-j-k from have* now that n-i-j-k is done + delete $haveij{"$i-$j"}; + delete $haveik{"$i-$k"}; + delete $havejk{"$j-$k"}; + # consider each of (i+1,j,k), (i,j+1,k) and (i,j,k+1) + foreach my $newt ( [$n*2, $i+1, $j, $k], + [$n*3, $i, $j+1, $k], + [$n*5, $i, $j, $k+1] ) + { + my( $newn, $x, $y, $z ) = @$newt; + #print "debug: found possible next n=$newn, x=$x, y=$y, z=$z\n"; + + # skip newn-x-y-z if we already known x-y-? or x-?-z or ?-x-z + # as this is a higher power combination that we will discover later + next if $haveij{"$x-$y"} || $haveik{"$x-$z"} || $havejk{"$y-$z"}; + + # ok, so newn-x-y-z is genuinely new: add it, first to have* + $haveij{"$x-$y"}++; + $haveik{"$x-$z"}++; + $havejk{"$y-$z"}++; + #print "debug: found actual next n=$newn, x=$x, y=$y, z=$z\n"; + + # second, insert $newn, $x, $y, $z into @next in sorted-by-N order + # - find first pos s.t. next[pos]>newn + my $pos; + for( $pos=0; $pos < @next && $next[$pos]->[0] < $newn; $pos ++ ) + { + } + # - add new item in at pos $pos: + splice( @next, $pos, 0, $newt ); + } + } + return @result; +} + + +# -------------------------------- Main program -------------------------------- + + +my $benchmark = shift // 0; +my $firstn = shift // 1000; + +if( $benchmark ) +{ + timethese( $benchmark, { + 'v1' => sub { firstn_regnos_v1( $firstn ) }, + 'v2' => sub { firstn_regnos_v2( $firstn ) }, + 'v3' => sub { firstn_regnos_v3( $firstn ) }, + 'v4' => sub { firstn_regnos_v4( $firstn ) }, + }); +} else +{ + print "calculating first $firstn regular numbers by v1 (generate and test):\n"; + my @result = firstn_regnos_v1( $firstn ); + my $s1 = join(',', @result); + print "they are: $s1\n"; + + print "calculating first $firstn regular numbers via v2 (todo+sort):\n"; + @result = firstn_regnos_v2( $firstn ); + my $s2 = join(',', @result); + #print "they are: $s2\n"; + + my $same = $s1 eq $s2 ? "same" : "different"; + print "v1 and v2: $same\n"; + + print "calculating first $firstn regular numbers via v3 (todo+find-smallest):\n"; + @result = firstn_regnos_v3( $firstn ); + my $s3 = join(',', @result); + + $same = $s1 eq $s3 ? "same" : "different"; + print "v1 and v3: $same\n"; + + print "calculating first $firstn regular numbers via v4 (clever):\n"; + @result = firstn_regnos_v4( $firstn ); + my $s4 = join(',', @result); + #print "v4: result $s4\n"; + + $same = $s1 eq $s4 ? "same" : "different"; + print "v1 and v4: $same\n"; +} diff --git a/challenge-003/duncan-c-white/perl5/ch-2.pl b/challenge-003/duncan-c-white/perl5/ch-2.pl new file mode 100755 index 0000000000..5109322548 --- /dev/null +++ b/challenge-003/duncan-c-white/perl5/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +# +# generate the first N rows of Pascal's triangle, no cleverness, just the +# basic formula. + + +use strict; +use warnings; + +use Function::Parameters; + +my $n = shift // 1000; + +my @curr = (1); # current row +my @next; # next row, one element longer than @curr + +for( my $row=1; $row<=$n; $row++ ) +{ + print "row $row: ".join(',',@curr)."\n"; + @next = ( ); + for( my $i=0; $i<=@curr; $i++ ) + { + $next[$i] = ($i==0?0:$curr[$i-1]) + ($i==@curr?0:$curr[$i]); + } + @curr = @next; +} diff --git a/challenge-003/nick-logan/perl5/ch-1.pl b/challenge-003/nick-logan/perl5/ch-1.pl new file mode 100644 index 0000000000..b76f7d6d92 --- /dev/null +++ b/challenge-003/nick-logan/perl5/ch-1.pl @@ -0,0 +1,29 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my $numbers_tried = 0; +my $numbers_found = 0; + +NUMBERS: while ($numbers_found != @ARGV[0]) { + + $numbers_tried++; + my $state = $numbers_tried; + while ($state != 1) { + if ($state % 2 == 0) { + $state /= 2; + } + elsif ($state % 3 == 0) { + $state /= 3; + } + elsif ($state % 5 == 0) { + $state /= 5; + } + else { + next NUMBERS; + } + } + $numbers_found++; + + print("$numbers_tried\n"); +} diff --git a/challenge-003/nick-logan/perl5/ch-2.pl b/challenge-003/nick-logan/perl5/ch-2.pl new file mode 100644 index 0000000000..10bcd74535 --- /dev/null +++ b/challenge-003/nick-logan/perl5/ch-2.pl @@ -0,0 +1,13 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my @state = (1,); +for (1 .. @ARGV[0]) { + print(join(" ", @state), "\n"); + my @row = map &{ sub ($_) { @state[$_] + (@state[$_ + 1] // 0) } }.(), (0 .. ($_ - 2)); + @state = (); + push(@state, 1); + push(@state, $_) for @row; + push(@state, 1); +} diff --git a/challenge-003/nick-logan/perl6/ch-1.p6 b/challenge-003/nick-logan/perl6/ch-1.p6 new file mode 100644 index 0000000000..b76f7d6d92 --- /dev/null +++ b/challenge-003/nick-logan/perl6/ch-1.p6 @@ -0,0 +1,29 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my $numbers_tried = 0; +my $numbers_found = 0; + +NUMBERS: while ($numbers_found != @ARGV[0]) { + + $numbers_tried++; + my $state = $numbers_tried; + while ($state != 1) { + if ($state % 2 == 0) { + $state /= 2; + } + elsif ($state % 3 == 0) { + $state /= 3; + } + elsif ($state % 5 == 0) { + $state /= 5; + } + else { + next NUMBERS; + } + } + $numbers_found++; + + print("$numbers_tried\n"); +} diff --git a/challenge-003/nick-logan/perl6/ch-2.p6 b/challenge-003/nick-logan/perl6/ch-2.p6 new file mode 100644 index 0000000000..10bcd74535 --- /dev/null +++ b/challenge-003/nick-logan/perl6/ch-2.p6 @@ -0,0 +1,13 @@ +# WARNING: this polyglot breaks best practices of both Perl 5 and Perl 6 in order to run on both + +my @ARGV = do { sub eval { &EVAL(@_) }; eval( ("0" and q|@*ARGS| or q|@ARGV|) ) }; + +my @state = (1,); +for (1 .. @ARGV[0]) { + print(join(" ", @state), "\n"); + my @row = map &{ sub ($_) { @state[$_] + (@state[$_ + 1] // 0) } }.(), (0 .. ($_ - 2)); + @state = (); + push(@state, 1); + push(@state, $_) for @row; + push(@state, 1); +} diff --git a/challenge-003/steve-rogerson/perl5/ch-1.pl b/challenge-003/steve-rogerson/perl5/ch-1.pl new file mode 100755 index 0000000000..e1378eaec3 --- /dev/null +++ b/challenge-003/steve-rogerson/perl5/ch-1.pl @@ -0,0 +1,29 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use List::Util 'min'; +use Const::Fast; +use 5.010; + + +sub hamming { + my ($arg) = @_; + $arg ||= 0; # pass 1 to restart. + state %s; + if (! %s or $arg ==1 ) { + %s = (1=>1); # 1 is the first hamming number. + } + my $next = min (keys %s); + delete $s{$next}; + for (2,3,5) { + $s{$next * $_} = 1; + } + return $next; +} + +my $i =0; +++$i, print hamming(), " " until $i > 20; +print "...\n"; + +++$i, hamming() until $i == 1690; +print ++$i, "-th: ", hamming(), "\n"; diff --git a/members.json b/members.json index 715990fb11..4a9d573fcf 100644 --- a/members.json +++ b/members.json @@ -22,6 +22,7 @@ "duncan-c-white" : "Duncan C. White", "eddy-hs" : "Eddy HS", "finley" : "Finley", + "fjwhittle" : "Francis Whittle", "fred-zinn" : "Fred Zinn", "freddie-b" : "Freddie B", "gustavo-chaves" : "Gustavo Chaves", diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 9501dd4f7f..06b58bbe2b 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -2,26 +2,45 @@ "series" : [ { "colorByPoint" : 1, - "name" : "Champions", "data" : [ { + "name" : "Andrezgz", + "y" : 2, + "drilldown" : "Andrezgz" + }, + { + "drilldown" : "Clive Holloway", "name" : "Clive Holloway", + "y" : 1 + }, + { + "drilldown" : "Daniel Mantovani", "y" : 1, - "drilldown" : "Clive Holloway" + "name" : "Daniel Mantovani" + }, + { + "drilldown" : "Duncan C. White", + "name" : "Duncan C. White", + "y" : 2 }, { - "drilldown" : "Gustavo Chaves", + "name" : "Francis Whittle", + "y" : 2, + "drilldown" : "Francis Whittle" + }, + { + "y" : 1, "name" : "Gustavo Chaves", - "y" : 1 + "drilldown" : "Gustavo Chaves" }, { - "drilldown" : "Dr James A. Smith", "y" : 4, - "name" : "Dr James A. Smith" + "name" : "Dr James A. Smith", + "drilldown" : "Dr James A. Smith" }, { - "name" : "Khalid", "y" : 2, + "name" : "Khalid", "drilldown" : "Khalid" }, { @@ -30,6 +49,11 @@ "name" : "Lars Balker" }, { + "drilldown" : "Nick Logan", + "name" : "Nick Logan", + "y" : 4 + }, + { "name" : "Chenyf", "y" : 2, "drilldown" : "Chenyf" @@ -45,67 +69,95 @@ "drilldown" : "Sergio Iglesias" }, { - "drilldown" : "Simon Proctor", + "y" : 2, "name" : "Simon Proctor", - "y" : 2 + "drilldown" : "Simon Proctor" + }, + { + "drilldown" : "Steve Rogerson", + "name" : "Steve Rogerson", + "y" : 1 } - ] + ], + "name" : "Champions" } ], - "xAxis" : { - "type" : "category" - }, - "legend" : { - "enabled" : 0 - }, - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "subtitle" : { - "text" : "[Champions: 9] Last updated at 2019-04-10 12:10:46 GMT" - }, - "plotOptions" : { - "series" : { - "dataLabels" : { - "format" : "{point.y}", - "enabled" : 1 - }, - "borderWidth" : 0 - } + "title" : { + "text" : "Perl Weekly Challenge - 003" }, "tooltip" : { - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", "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/>" }, + "xAxis" : { + "type" : "category" + }, "drilldown" : { "series" : [ { - "id" : "Clive Holloway", + "name" : "Andrezgz", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "id" : "Andrezgz" + }, + { + "name" : "Clive Holloway", "data" : [ [ "Perl 5", 1 ] ], - "name" : "Clive Holloway" + "id" : "Clive Holloway" }, { + "id" : "Daniel Mantovani", "data" : [ [ "Perl 5", 1 ] ], + "name" : "Daniel Mantovani" + }, + { + "id" : "Duncan C. White", + "data" : [ + [ + "Perl 5", + 2 + ] + ], + "name" : "Duncan C. White" + }, + { + "data" : [ + [ + "Perl 6", + 2 + ] + ], + "id" : "Francis Whittle", + "name" : "Francis Whittle" + }, + { "name" : "Gustavo Chaves", + "data" : [ + [ + "Perl 5", + 1 + ] + ], |
