diff options
| author | 冯昶 <fengchang@novel-supertv.com> | 2021-05-03 18:31:36 +0800 |
|---|---|---|
| committer | 冯昶 <fengchang@novel-supertv.com> | 2021-05-03 18:31:36 +0800 |
| commit | 81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8 (patch) | |
| tree | e4df369a6349802da33aa6d94b7fe745041a9955 /challenge-109 | |
| parent | 0142974e5f11adadbaa7ca8d71de9db345318519 (diff) | |
| parent | 0381a39b17ccd040302474f25d3c1cbbef703327 (diff) | |
| download | perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.gz perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.tar.bz2 perlweeklychallenge-club-81252bda7fb7bcc9e9e153a6b3d268ab8c1a38c8.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-109')
| -rw-r--r-- | challenge-109/cheok-yin-fung/java/NBoxesJavaFX.java | 2 | ||||
| -rw-r--r-- | challenge-109/james-smith/perl/ch-1.pl | 22 | ||||
| -rw-r--r-- | challenge-109/james-smith/perl/ch-2.pl | 5 | ||||
| -rw-r--r-- | challenge-109/mohammad-anwar/blog1.txt | 1 | ||||
| -rw-r--r-- | challenge-109/sgreen/README.md | 2 | ||||
| -rw-r--r-- | challenge-109/sgreen/blog.txt | 1 |
6 files changed, 15 insertions, 18 deletions
diff --git a/challenge-109/cheok-yin-fung/java/NBoxesJavaFX.java b/challenge-109/cheok-yin-fung/java/NBoxesJavaFX.java index ad507def6e..3ae566171b 100644 --- a/challenge-109/cheok-yin-fung/java/NBoxesJavaFX.java +++ b/challenge-109/cheok-yin-fung/java/NBoxesJavaFX.java @@ -122,8 +122,6 @@ public class NBoxesJavaFX extends Application group.getChildren().add(shape[i]); } - Rectangle shape1 = new Rectangle(); - Text[] text = new Text[M]; Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 15); for (int j=0; j<M; j++) { diff --git a/challenge-109/james-smith/perl/ch-1.pl b/challenge-109/james-smith/perl/ch-1.pl index 1b89226a6a..6fccc59edd 100644 --- a/challenge-109/james-smith/perl/ch-1.pl +++ b/challenge-109/james-smith/perl/ch-1.pl @@ -19,7 +19,7 @@ is( chowla_for($_), $answer[ $_ ] ) foreach 1..20; done_testing(); ## We will quickly run benchmarking... -## This suggests the for loop to be approximately 40-50% +## This suggests the for loop to be approximately 40% ## faster than the map solution... ## It is also 9 characters shorter... @@ -30,19 +30,17 @@ cmpthese(1_000_000, { ## ## Rate Map For -## Map 38670/s -- -33% -## For 57670/s 49% -- +## Map 59524/s -- -26% +## For 79936/s 34% -- ## -sub chowla_map { - my ($t,$n) = (0,@_); ## First attempt - the one-liner is to write this as a map, ## we add $t at the end which is the value returned - ( map { (($n%$_) || ($t+=$_)) && () } 2..$n-1 ), $t; +sub chowla_map { + my ($t,$n) = (0,@_); + ( map { (($n%$_) || ($t+=$_)) && () } 2..$n>>1 ), $t; } -sub chowla_for { - my($t,$n)=(0,@_); ## This time we won't write this as a nasty map/reduce solution... ## @@ -55,12 +53,12 @@ sub chowla_for { ## can be rewritten as: ## ($condition)||($fun()) ## * in perl `foreach` and `for` are synonymous - so we can shorten - - ($n%$_)||($t+=$_) for 2..$n-1; - - ## Now a quick "shortening" - if there is no specific return + ## Finally a quick "shortening" - if there is no specific return ## statement - we can just omit the return in the last statement... +sub chowla_for { + my($t,$n)=(0,@_); + ($n%$_)||($t+=$_) for 2..$n>>1; $t; } diff --git a/challenge-109/james-smith/perl/ch-2.pl b/challenge-109/james-smith/perl/ch-2.pl index 436e0fca19..bafd89bff8 100644 --- a/challenge-109/james-smith/perl/ch-2.pl +++ b/challenge-109/james-smith/perl/ch-2.pl @@ -67,8 +67,6 @@ say ''; sub sep { say '------------------------------------------------------------------------'; } sub show { say "@{$_}" foreach @{$_[0]}; } -sub four_square { - ## For a start we make the observation that ## ## $a + 2$b + $c + 2$d + $e + 2$f + $g = $n * 4 where $n is the total of a square @@ -94,6 +92,7 @@ sub four_square { ## ## We push any valid results to the array +sub four_square { my ($t,@n1,@res) = (0,@_); $t+=$_ foreach @n1; foreach my $b ( @n1 ) { @@ -110,7 +109,6 @@ sub four_square { return \@res; } -sub four_square_non_unique { ## Now let us make no assumption about the numbers... ## We choose 3 from the list... ## We then compute n (and check for no remainder) @@ -123,6 +121,7 @@ sub four_square_non_unique { ## will end up with 2 entries in the list ## where you swap the equivalent values... +sub four_square_non_unique { my ($t,$check,@n1,%res) = (0,"@{[sort @_]}",@_); $t+=$_ foreach @n1; foreach my $i ( 0..@n1-1 ) { diff --git a/challenge-109/mohammad-anwar/blog1.txt b/challenge-109/mohammad-anwar/blog1.txt new file mode 100644 index 0000000000..4aa1d726d9 --- /dev/null +++ b/challenge-109/mohammad-anwar/blog1.txt @@ -0,0 +1 @@ +https://www.youtube.com/watch?v=DvW9Jig42cg diff --git a/challenge-109/sgreen/README.md b/challenge-109/sgreen/README.md index 94ad2ed1db..b0c87bc76f 100644 --- a/challenge-109/sgreen/README.md +++ b/challenge-109/sgreen/README.md @@ -1,3 +1,3 @@ # The Weekly Challenge 109 -Solution by Simon Green. [Blog]() +Solution by Simon Green. [Blog](https://dev.to/simongreennet/weekly-challenge-109-4je2) diff --git a/challenge-109/sgreen/blog.txt b/challenge-109/sgreen/blog.txt new file mode 100644 index 0000000000..58dcac2565 --- /dev/null +++ b/challenge-109/sgreen/blog.txt @@ -0,0 +1 @@ +https://dev.to/simongreennet/weekly-challenge-109-4je2 |
