diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-13 00:49:01 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-13 00:49:01 +0100 |
| commit | 07f5af51a34a3ce03762f49f18693cc8dd1392d6 (patch) | |
| tree | be09eea6e8b485523928d3198e45d1896c4b25be | |
| parent | 864b28b1a7417493ab8f94934e491909576230da (diff) | |
| download | perlweeklychallenge-club-07f5af51a34a3ce03762f49f18693cc8dd1392d6.tar.gz perlweeklychallenge-club-07f5af51a34a3ce03762f49f18693cc8dd1392d6.tar.bz2 perlweeklychallenge-club-07f5af51a34a3ce03762f49f18693cc8dd1392d6.zip | |
- Added solutions by Laurent Rosenfeld.
29 files changed, 1974 insertions, 1806 deletions
diff --git a/challenge-173/laurent-rosenfeld/bc/ch-2.bc b/challenge-173/laurent-rosenfeld/bc/ch-2.bc new file mode 100644 index 0000000000..b10eacbc4a --- /dev/null +++ b/challenge-173/laurent-rosenfeld/bc/ch-2.bc @@ -0,0 +1,9 @@ +n = 2 +print n, "\n" +count = 1 +while (count < 10) { + n = (n - 1) * n + 1 + print n, "\n" + count += 1 +} +quit diff --git a/challenge-173/laurent-rosenfeld/blog.txt b/challenge-173/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..b474a60ea6 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2022/07/perl-weekly-challenge-173-esthetic-number-and-sylvesters-sequence.html diff --git a/challenge-173/laurent-rosenfeld/julia/ch-1.jl b/challenge-173/laurent-rosenfeld/julia/ch-1.jl new file mode 100644 index 0000000000..063b9f4276 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/julia/ch-1.jl @@ -0,0 +1,13 @@ +function is_esthetic(num) + n = string(num) + for i in 2:length(n) + if abs(n[i] - n[i-1]) != 1 + return false + end + end + return true +end + +for test in [5456, 120, 121, 23456, 2346, 7654567, 765467] + println("$test\t", is_esthetic(test) ? "Esthetic" : "Non esthetic") +end diff --git a/challenge-173/laurent-rosenfeld/julia/ch-2.jl b/challenge-173/laurent-rosenfeld/julia/ch-2.jl new file mode 100644 index 0000000000..bde783e20b --- /dev/null +++ b/challenge-173/laurent-rosenfeld/julia/ch-2.jl @@ -0,0 +1,6 @@ +s = BigInt(2) +println(s) +for i in 1:9 + s = s * (s - 1) + 1 + println(s) +end diff --git a/challenge-173/laurent-rosenfeld/perl/ch-1.pl b/challenge-173/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..449f134865 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,14 @@ +use strict; +use warnings; +use feature "say"; + +sub is_esthetic { + my @d = split //, shift; # get an array of digits + for my $i (1..$#d) { + return 0 if abs($d[$i] - $d[$i -1 ]) != 1; + } + return 1; +} +for my $test (qw<5456 120 121 23456 2346 7654567 765467>) { + say sprintf("%-9d", $test), is_esthetic($test) ? "is esthetic" : "is not esthetic"; +} diff --git a/challenge-173/laurent-rosenfeld/perl/ch-2.pl b/challenge-173/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..7cedfe165d --- /dev/null +++ b/challenge-173/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,16 @@ +use strict; +use warnings; +use feature "say"; +use bigint; + +sub prod { + my $prod = 1; + $prod *= $_ for @_; + return $prod; +} + +my @s = (2); +while (@s < 10) { + push @s, 1 + prod @s; +} +say for @s; diff --git a/challenge-173/laurent-rosenfeld/python/ch-1.py b/challenge-173/laurent-rosenfeld/python/ch-1.py new file mode 100644 index 0000000000..6711b299a8 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/python/ch-1.py @@ -0,0 +1,12 @@ +def is_esthetic(m): + n = str(m) + for i in range(1, len(n)): + if abs(int(n[i]) - int(n[i - 1 ])) != 1: + return False + return True + +for test in [5456, 120, 121, 23456, 2346, 7654567, 765467]: + if is_esthetic(test): + print("{:<9d} is esthetic".format(test)) + else: + print("{:<9d} is not esthetic".format(test)) diff --git a/challenge-173/laurent-rosenfeld/python/ch-2.py b/challenge-173/laurent-rosenfeld/python/ch-2.py new file mode 100644 index 0000000000..7687e7a464 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/python/ch-2.py @@ -0,0 +1,5 @@ +s = [2]; +for i in range(9): + s.append(s[-1] * (s[-1] - 1) + 1) +for j in s: + print(j) diff --git a/challenge-173/laurent-rosenfeld/raku/ch-1.raku b/challenge-173/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..ab422ca880 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,8 @@ +sub is-esthetic ($n) { + my @d = $n.comb; # get an array of digits + return False if abs(@d[$_] - @d[$_-1]) != 1 for 1..@d.end; + return True; +} +for <5456 120 121 23456 2346 7654567 765467> -> $test { + say $test.fmt("%-9d"), is-esthetic($test) ?? "is esthetic" !! "is not esthetic"; +} diff --git a/challenge-173/laurent-rosenfeld/raku/ch-2.raku b/challenge-173/laurent-rosenfeld/raku/ch-2.raku new file mode 100644 index 0000000000..a07d25bb6a --- /dev/null +++ b/challenge-173/laurent-rosenfeld/raku/ch-2.raku @@ -0,0 +1,5 @@ +my @s = 2; +while @s.elems < 10 { + push @s, 1 + [*] @s; +} +.say for @s; diff --git a/challenge-173/laurent-rosenfeld/ring/ch-1.ring b/challenge-173/laurent-rosenfeld/ring/ch-1.ring new file mode 100644 index 0000000000..812110474c --- /dev/null +++ b/challenge-173/laurent-rosenfeld/ring/ch-1.ring @@ -0,0 +1,17 @@ +for test in [5456, 120, 121, 23456, 2346, 7654567, 765467] + see test + if is_esthetic(test) + see " is esthetic" + nl + else + see " is not esthetic" + nl + ok +next + +func is_esthetic (num) + n = "" + num + for i = 2 to len(n) + if fabs(n[i] - n[i-1]) != 1 + return false + ok + next + return true diff --git a/challenge-173/laurent-rosenfeld/ring/ch-2.ring b/challenge-173/laurent-rosenfeld/ring/ch-2.ring new file mode 100644 index 0000000000..b67bc2768a --- /dev/null +++ b/challenge-173/laurent-rosenfeld/ring/ch-2.ring @@ -0,0 +1,6 @@ +s = 2; +see s + nl +for i = 1 to 9 + s = s * (s - 1) + 1 + see s + nl +next diff --git a/challenge-173/laurent-rosenfeld/ruby/ch-1.rb b/challenge-173/laurent-rosenfeld/ruby/ch-1.rb new file mode 100644 index 0000000000..bf4d162263 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/ruby/ch-1.rb @@ -0,0 +1,18 @@ +def is_esthetic(m) + n = m.to_s + for i in 1..(n.length - 1) + if (n[i].to_i - n[i-1].to_i).abs != 1 + return false + end + end + return true +end + +for test in [ 5456, 120, 121, 23456, 2346, 7654567, 765467] + printf "%-9d ", test + if is_esthetic(test) + print("is esthetic\n") + else + print("is not esthetic\n") + end +end diff --git a/challenge-173/laurent-rosenfeld/ruby/ch-2.rb b/challenge-173/laurent-rosenfeld/ruby/ch-2.rb new file mode 100644 index 0000000000..0890b30498 --- /dev/null +++ b/challenge-173/laurent-rosenfeld/ruby/ch-2.rb @@ -0,0 +1,7 @@ +# Ruby automatically switches to Bignum when needed +s = 2 +print("#{s}\n") +for i in 1..9 + s = s * (s - 1) + 1 + print("#{s}\n") +end diff --git a/challenge-173/laurent-rosenfeld/scala/ch-2.scala b/challenge-173/laurent-rosenfeld/scala/ch-2.scala new file mode 100644 index 0000000000..f08aee7b2b --- /dev/null +++ b/challenge-173/laurent-rosenfeld/scala/ch-2.scala @@ -0,0 +1,8 @@ +object sylvester extends App { + var n = BigInt(2) + println(n) + for (i <- 1 to 9) { + n = n * (n - 1) + 1 + println(n) + } +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 3d73216786..bce0231769 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,49 +1,28 @@ { - "tooltip" : { - "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/>", - "followPointer" : 1 - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "chart" : { - "type" : "column" - }, - "subtitle" : { - "text" : "[Champions: 14] Last updated at 2022-07-12 23:24:17 GMT" - }, - "title" : { - "text" : "The Weekly Challenge - 173" - }, - "legend" : { - "enabled" : 0 - }, "drilldown" : { "series" : [ { + "name" : "Cheok-Yin Fung", "data" : [ [ "Perl", 1 ] ], - "name" : "Cheok-Yin Fung", "id" : "Cheok-Yin Fung" }, { + "id" : "E. Choroba", + "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ], - "name" : "E. Choroba", - "id" : "E. Choroba" + ] }, { + "name" : "Jaldhar H. Vyas", "data" : [ [ "Perl", @@ -58,8 +37,7 @@ 1 ] ], - "id" : "Jaldhar H. Vyas", - "name" : "Jaldhar H. Vyas" + "id" : "Jaldhar H. Vyas" }, { "id" : "James Smith", @@ -76,6 +54,24 @@ ] }, { + "id" : "Laurent Rosenfeld", + "data" : [ + [ + "Perl", + 2 + ], + [ + "Raku", + 2 + ], + [ + "Blog", + 1 + ] + ], + "name" : "Laurent Rosenfeld" + }, + { "id" : "Luca Ferrari", "name" : "Luca Ferrari", "data" : [ @@ -90,34 +86,34 @@ ] }, { + "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], - "name" : "Mark Anderson", - "id" : "Mark Anderson" + "name" : "Mark Anderson" }, { + "id" : "Matthew Neleigh", "data" : [ [ "Perl", 2 ] ], - "id" : "Matthew Neleigh", "name" : "Matthew Neleigh" }, { - "id" : "Niels van Dijke", "name" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] - ] + ], + "id" : "Niels van Dijke" }, { "data" : [ @@ -130,42 +126,41 @@ 1 ] ], - "id" : "Peter Campbell Smith", - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { + "name" : "Philippe Bricout", "data" : [ [ "Perl", 1 ] ], - "name" : "Philippe Bricout", "id" : "Philippe Bricout" }, { + "id" : "Robert Ransbottom", + "name" : "Robert Ransbottom", "data" : [ [ "Raku", 2 ] - ], - "name" : "Robert Ransbottom", - "id" : "Robert Ransbottom" + ] }, { + "name" : "Simon Proctor", "data" : [ [ "Raku", 2 ] ], - "id" : "Simon Proctor", - "name" : "Simon Proctor" + "id" : "Simon Proctor" }, { "name" : "Stephen G Lynn", - "id" : "Stephen G Lynn", "data" : [ [ "Perl", @@ -179,7 +174,8 @@ "Blog", 1 ] - ] + ], + "id" : "Stephen G Lynn" }, { "data" : [ @@ -192,26 +188,47 @@ 1 ] ], - "id" : "W. Luis Mochan", - "name" : "W. Luis Mochan" + "name" : "W. Luis Mochan", + "id" : "W. Luis Mochan" } ] }, + "legend" : { + "enabled" : 0 + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, "plotOptions" : { "series" : { + "borderWidth" : 0, "dataLabels" : { "format" : "{point.y}", "enabled" : 1 - }, - "borderWidth" : 0 + } } }, "xAxis" : { "type" : "category" }, + "chart" : { + "type" : "column" + }, + "title" : { + "text" : "The Weekly Challenge - 173" + }, + "tooltip" : { + "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/>", + "followPointer" : 1 + }, + "subtitle" : { + "text" : "[Champions: 15] Last updated at 2022-07-12 23:47:23 GMT" + }, "series" : [ { - "name" : "The Weekly Challenge - 173", "data" : [ { "y" : 1, @@ -220,13 +237,13 @@ }, { "drilldown" : "E. Choroba", - "name" : "E. Choroba", - "y" : 2 + "y" : 2, + "name" : "E. Choroba" }, { - "drilldown" : "Jaldhar H. Vyas", + "y" : 5, "name" : "Jaldhar H. Vyas", - "y" : 5 + "drilldown" : "Jaldhar H. Vyas" }, { "name" : "James Smith", @@ -234,29 +251,34 @@ "drilldown" : "James Smith" }, { + "drilldown" : "Laurent Rosenfeld", + "y" : 5, + "name" : "Laurent Rosenfeld" + }, + { "name" : "Luca Ferrari", "y" : 8, "drilldown" : "Luca Ferrari" }, { - "name" : "Mark Anderson", "y" : 2, + "name" : "Mark Anderson", "drilldown" : "Mark Anderson" }, { - "y" : 2, + "drilldown" : "Matthew Neleigh", "name" : "Matthew Neleigh", - "drilldown" : "Matthew Neleigh" + "y" : 2 }, { - "drilldown" : "Niels van Dijke", + "name" : "Niels van Dijke", "y" : 2, - "name" : "Niels van Dijke" + "drilldown" : "Niels van Dijke" }, { - "drilldown" : "Peter Campbell Smith", + "y" : 3, "name" : "Peter Campbell Smith", - "y" : 3 + "drilldown" : "Peter Campbell Smith" }, { "drilldown" : "Philippe Bricout", @@ -264,9 +286,9 @@ "y" : 1 }, { - "name" : "Robert Ransbottom", + "drilldown" : "Robert Ransbottom", "y" : 2, - "drilldown" : "Robert Ransbottom" + "name" : "Robert Ransbottom" }, { "drilldown" : "Simon Proctor", @@ -279,11 +301,12 @@ "name" : "Stephen G Lynn" }, { - "drilldown" : "W. Luis Mochan", + "y" : 3, "name" : "W. Luis Mochan", - "y" : 3 + "drilldown" : "W. Luis Mochan" } ], + "name" : "The Weekly Challenge - 173", "colorByPoint" : 1 } ] diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 1f24897310..730dbde996 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,63 +1,63 @@ { - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2022]" + "yAxis" : { + "min" : 0, + "title" : { + "text" : null + } }, "legend" : { "enabled" : "false" }, - "subtitle" : { - "text" : "Last updated at 2022-07-12 23:24:17 GMT" + "xAxis" : { + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + }, + "type" : "category" }, "chart" : { "type" : "column" }, - "yAxis" : { - "title" : { - "text" : null - }, - "min" : 0 - }, "tooltip" : { "pointFormat" : "<b>{point.y:.0f}</b>" }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2022]" + }, + "subtitle" : { + "text" : "Last updated at 2022-07-12 23:47:23 GMT" + }, "series" : [ { - "name" : "Contributions", "dataLabels" : { - "enabled" : "true", - "rotation" : -90, - "align" : "right", "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" }, - "color" : "#FFFFFF", "format" : "{point.y:.0f}", - "y" : 10 + "enabled" : "true", + "y" : 10, + "color" : "#FFFFFF", + "rotation" : -90, + "align" : "right" }, "data" : [ [ "Blog", - 2698 + 2699 ], [ "Perl", - 8415 + 8417 ], [ "Raku", - 5003 + 5005 ] - ] - } - ], - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } + ], + "name" : "Contributions" } - } + ] } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index e675b5d244..4e24798153 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,23 +1,893 @@ { - "chart" : { - "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } + "title" : { + "text" : "The Weekly Challenge Language" }, "tooltip" : { - "followPointer" : "true", + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>", "headerFormat" : "<span style=\"font-size:11px\"></span>", - "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" + "followPointer" : "true" }, - "title" : { - "text" : "The Weekly Challenge Language" + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2022-07-12 23:47:23 GMT" }, + "series" : [ + { + "colorByPoint" : "true", + "name" : "The Weekly Challenge Languages", + "data" : [ + { + "drilldown" : "001", + "y" : 161, + "name" : "#001" + }, + { + "drilldown" : "002", + "y" : 125, + "name" : "#002" + }, + { + "name" : "#003", + "y" : 83, + "drilldown" : "003" + }, + { + "drilldown" : "004", + "name" : "#004", + "y" : 99 + }, + { + "drilldown" : "005", + "name" : "#005", + "y" : 78 + }, + { + "drilldown" : "006", + "y" : 58, + "name" : "#006" + }, + { + "drilldown" : "007", + "y" : 65, + "name" : "#007" + }, + { + "drilldown" : "008", + "name" : "#008", + "y" : 78 + }, + { + "y" : 76, + "name" : "#009", + "drilldown" : "009" + }, + { + "y" : 65, + "name" : "#010", + "drilldown" : "010" + }, + { + "drilldown" : "011", + "y" : 85, + "name" : "#011" + }, + { + "name" : "#012", + "y" : 89, + "drilldown" : "012" + }, + { + "drilldown" : "013", + "y" : 85, + "name" : "#013" + }, + { + "drilldown" : "014", + "name" : "#014", + "y" : 101 + }, + { + "drilldown" : "015", + "y" : 99, + "name" : "#015" + }, + { + "name" : "#016", + "y" : 71, + "drilldown" : "016" + }, + { + "drilldown" : "017", + "name" : "#017", + "y" : 84 + }, + { + "name" : "#018", + "y" : 81, + "drilldown" : "018" + }, + { + "y" : 103, + "name" : "#019", + "drilldown" : "019" + }, + { + "drilldown" : "020", + "y" : 101, + "name" : "#020" + }, + { + "name" : "#021", + "y" : 72, + "drilldown" : "021" + }, + { + "y" : 68, + "name" : "#022", + "drilldown" : "022" + }, + { + "drilldown" : "023", + "name" : "#023", + "y" : 97 + }, + { + "name" : "#024", + "y" : 75, + "drilldown" : "024" + }, + { + "drilldown" : "025", + "name" : "#025", + "y" : 59 + }, + { + "name" : "#026", + "y" : 74, + "drilldown" : "026" + }, + { + "name" : "#027", + "y" : 62, + "drilldown" : "027" + }, + { + "y" : 82, + "name" : "#028", + "drilldown" : "028" + }, + { + "y" : 81, + "name" : "#029", + "drilldown" : "029" + }, + { + "name" : "#030", + "y" : 119, + "drilldown" : "030" + }, + { + "drilldown" : "031", + "name" : "#031", + "y" : 91 + }, + { + "name" : "#032", + "y" : 96, + "drilldown" : "032" + }, + { + "y" : 112, + "name" : "#033", + "drilldown" : "033" + }, + { + "drilldown" : "034", + "y" : 66, + "name" : "#034" + }, + { + "name" : "#035", + "y" : 66, + "drilldown" : "035" + }, + { + "drilldown" : "036", + "y" : 70, + "name" : "#036" + }, + { + "y" : 69, + "name" : "#037", + "drilldown" : "037" + }, + { + "drilldown" : "038", + "y" : 70, + "name" : "#038" + }, + { + "drilldown" : "039", + "y" : 64, + "name" : "#039" + }, + { + "name" : "#040", + "y" : 75, + "drilldown" : "040" + }, + { |
