diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-19 11:05:57 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-11-19 11:05:57 +0000 |
| commit | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (patch) | |
| tree | 3f6e35b8583ff50174ec7fac6e2b8b60c463efe6 | |
| parent | 1e1f2f3f3e08eba010e55eccb5678e215dfce7e9 (diff) | |
| download | perlweeklychallenge-club-bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56.tar.gz perlweeklychallenge-club-bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56.tar.bz2 perlweeklychallenge-club-bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56.zip | |
- Added more solutions by Robert DiCicco.
| -rw-r--r-- | challenge-191/robert-dicicco/julia/ch-2.jl | 189 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/perl/ch-2.pl | 181 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/raku/ch-2.raku | 159 | ||||
| -rw-r--r-- | challenge-191/robert-dicicco/ruby/ch-2.rb | 163 | ||||
| -rw-r--r-- | stats/pwc-current.json | 350 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 74 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 1216 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 716 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 42 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 40 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 50 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 50 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 110 | ||||
| -rw-r--r-- | stats/pwc-summary-271-300.json | 36 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 36 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 104 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 56 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 604 |
19 files changed, 2483 insertions, 1791 deletions
diff --git a/challenge-191/robert-dicicco/julia/ch-2.jl b/challenge-191/robert-dicicco/julia/ch-2.jl new file mode 100644 index 0000000000..bb3f6973c7 --- /dev/null +++ b/challenge-191/robert-dicicco/julia/ch-2.jl @@ -0,0 +1,189 @@ +#!/usr/bin/env julia + + + +#= + +AUTHOR: Robert DiCicco + +DATE: 2022-11-17 + +Challenge 191 Cute List ( Julia ) + + + +You are given an integer, 0 < $n <= 15. + + + +Write a script to find the number of orderings of numbers that form a cute list. + + + +With an input @list = (1, 2, 3, .. $n) for positive integer $n, an ordering of @list is cute if for every entry, indexed with a base of 1, either + + + +1) $list[$i] is evenly divisible by $i + +or + +2) $i is evenly divisible by $list[$i] + + + +Example + + + +Input: $n = 2 + +Ouput: 2 + + + +Since $n = 2, the list can be made up of two integers only i.e. 1 and 2. + +Therefore we can have two list i.e. (1,2) and (2,1). + + + +@list = (1,2) is cute since $list[1] = 1 is divisible by 1 and $list[2] = 2 is divisible by 2. + +=# + + + +using Combinatorics + +using Printf + + + +function checkArgs(args) + + global num + + try + + num = parse(Int64, args) + + catch + + println("Error: Argument must be an integer") + + exit(0) + + finally + + if num < 1 || num > 15 + + println("Error: Argument must be > 0 and less than 16") + + exit(0) + + else + + main(num) + + end + + end + +end + + + +function main(arg) + +arr = collect(1:arg) + +@printf("\n\nInput: %s\n", arg) + +p = collect(permutations(arr,length(arr))) + +for suba in p + + res = 0 + + res2 = 0 + + success = 0 + + for x in 1:length(suba) + + res = suba[x] % x + + res2 = x % suba[x] + + if ((res == 0) || (res2 == 0) ) + + success += 1 + + end + + if success == length(suba) + + @printf("%s is cute!\n", suba) + + end + + end + +end + +end + + + +for mynum in ARGS + + checkArgs(mynum) + +end + + + +#= + +SAMPLE OUTPUT + +julia .\CuteList.jl 2 3 4 + +Input: 2 + +[1, 2] is cute! + +[2, 1] is cute! + + + +Input: 3 + +[1, 2, 3] is cute! + +[2, 1, 3] is cute! + +[3, 2, 1] is cute! + + + +Input: 4 + +[1, 2, 3, 4] is cute! + +[1, 4, 3, 2] is cute! + +[2, 1, 3, 4] is cute! + +[2, 4, 3, 1] is cute! + +[3, 2, 1, 4] is cute! + +[3, 4, 1, 2] is cute! + +[4, 1, 3, 2] is cute! + +[4, 2, 3, 1] is cute! + +=# diff --git a/challenge-191/robert-dicicco/perl/ch-2.pl b/challenge-191/robert-dicicco/perl/ch-2.pl new file mode 100644 index 0000000000..8510eee8b7 --- /dev/null +++ b/challenge-191/robert-dicicco/perl/ch-2.pl @@ -0,0 +1,181 @@ +#!/usr/bin/env perl + + + +=begin pod + +AUTHOR: Robert DiCicco + +DATE: 2022-11-17 + +Challenge 191 Cute List ( Perl ) + + + +You are given an integer, 0 < $n <= 15. + + + +Write a script to find the number of orderings of numbers that form a cute list. + + + +With an input @list = (1, 2, 3, .. $n) for positive integer $n, an ordering of @list is cute if for every entry, indexed with a base of 1, either + + + +1) $list[$i] is evenly divisible by $i + +or + +2) $i is evenly divisible by $list[$i] + + + +Example + + + +Input: $n = 2 + +Ouput: 2 + + + +Since $n = 2, the list can be made up of two integers only i.e. 1 and 2. + +Therefore we can have two list i.e. (1,2) and (2,1). + + + +@list = (1,2) is cute since $list[1] = 1 is divisible by 1 and $list[2] = 2 is divisible by 2. + +=cut + + + +use strict; + +use warnings; + +use Algorithm::Permute; + +use feature qw/say/; + + + +my @arr = ([1,2,3], [1,2,3,4], [1,2,3,4,5]); + + + +sub main { + + my $arg = shift; + + my @a = (1..$arg); + + my $len = scalar(@a); + + say "Input: $len"; + + my $p = Algorithm::Permute->new(\@a, $len); + + while ( my @suba = $p->next) { + + my $res = 0; + + my $res2 = 0; + + my $success = 0; + + for my $x (0..$len-1){ + + $res = $suba[$x] % ($x+1); + + $res2 = ($x+1) % $suba[$x]; + + if (($res == 0) || ($res2 == 0) ) { + + $success++; + + } + + if ($success == $len) { + + print("\[@suba\] is cute!\n"); + + } + + } + + } + + print("\n"); + +} + + + +for my $arg (@ARGV) { + + if (( $arg <1) || ($arg > 15)) { + + say "Error: supplied arg = $arg. arg must be greater than 0 and less than 16"; + + exit(1); + + } + + main($arg); + +} + + + +=begin pod + +SAMPLE OUTPUT + + + +perl .\CuteList.pl 2 3 4 + +Input: 2 + +[2 1] is cute! + +[1 2] is cute! + + + +Input: 3 + +[3 2 1] is cute! + +[2 1 3] is cute! + +[1 2 3] is cute! + + + +Input: 4 + +[3 2 1 4] is cute! + +[4 2 3 1] is cute! + +[2 4 3 1] is cute! + +[2 1 3 4] is cute! + +[3 4 1 2] is cute! + +[4 1 3 2] is cute! + +[1 4 3 2] is cute! + +[1 2 3 4] is cute! + + + +=cut diff --git a/challenge-191/robert-dicicco/raku/ch-2.raku b/challenge-191/robert-dicicco/raku/ch-2.raku new file mode 100644 index 0000000000..e19cf11c46 --- /dev/null +++ b/challenge-191/robert-dicicco/raku/ch-2.raku @@ -0,0 +1,159 @@ +use v6; + +#`{ + + AUTHOR: Robert DiCicco + + DATE: 2022-11-17 + + Challenge 191 Cute List ( Raku ) + + + + You are given an integer, 0 < $n <= 15. + + + + Write a script to find the number of orderings of numbers that form a cute list. + + + + With an input @list = (1, 2, 3, .. $n) for positive integer $n, an ordering of @list is cute if for every entry, indexed with a base of 1, either + + + + 1) $list[$i] is evenly divisible by $i + + or + + 2) $i is evenly divisible by $list[$i] + + + + Example + + + + Input: $n = 2 + + Ouput: 2 + + + + Since $n = 2, the list can be made up of two integers only i.e. 1 and 2. + + Therefore we can have two list i.e. (1,2) and (2,1). + + + + @list = (1,2) is cute since $list[1] = 1 is divisible by 1 and $list[2] = 2 is divisible by 2. + + + +} + + + +sub main($n) { + + print "Input: n = $n\n"; + + my @arr = 1..$n; + + my $len = @arr.elems; + + for @arr.permutations -> @suba { + + my $res = 0; + + my $res2 = 0; + + my $success = 0; + + for 0..($len-1) -> $x { + + $res = @suba[$x] % ($x+1); + + $res2 = ($x+1) % @suba[$x]; + + if (($res == 0) || ($res2 == 0)) { + + $success++; + + } + + if ($success == $len) { + + print "[" ~ @suba ~ "\] is cute!\n"; + + } + + } + + } + + put " "; + +} + + + +for @*ARGS -> $arg { + + if (( $arg < 1 ) || ( $arg > 15 )) { + + say "Error: supplied argument = $arg. Argument must be greater than 0 and less than 16"; + + exit(1); + + } + + main($arg); + +} + + + +#`{ + +SAMPLE OUTPUT + +raku .\CuteList.rk 2 3 4 + +Input: n = 2 + +[1 2] is cute! + +[2 1] is cute! + + + +Input: n = 3 + +[1 2 3] is cute! + +[2 1 3] is cute! + +[3 2 1] is cute! + + + +Input: n = 4 + +[1 2 3 4] is cute! + +[1 4 3 2] is cute! + +[2 1 3 4] is cute! + +[2 4 3 1] is cute! + +[3 2 1 4] is cute! + +[3 4 1 2] is cute! + +[4 1 3 2] is cute! + +[4 2 3 1] is cute! + +} diff --git a/challenge-191/robert-dicicco/ruby/ch-2.rb b/challenge-191/robert-dicicco/ruby/ch-2.rb new file mode 100644 index 0000000000..97fb0b01be --- /dev/null +++ b/challenge-191/robert-dicicco/ruby/ch-2.rb @@ -0,0 +1,163 @@ +#!/usr/bin/env ruby + + + +=begin + +AUTHOR: Robert DiCicco + +DATE: 2022-11-17 + +Challenge 191 Cute List ( Ruby ) + + + +You are given an integer, 0 < $n <= 15. + + + +Write a script to find the number of orderings of numbers that form a cute list. + + + +With an input @list = (1, 2, 3, .. $n) for positive integer $n, an ordering of @list is cute if for every entry, indexed with a base of 1, either + + + +1) $list[$i] is evenly divisible by $i + +or + +2) $i is evenly divisible by $list[$i] + + + +Example + + + +Input: $n = 2 + +Ouput: 2 + + + +Since $n = 2, the list can be made up of two integers only i.e. 1 and 2. + +Therefore we can have two list i.e. (1,2) and (2,1). + + + +@list = (1,2) is cute since $list[1] = 1 is divisible by 1 and $list[2] = 2 is divisible by 2. + +=end + + + +def main(n) + + arr = (1..n.to_i).to_a + + len = arr.length() + + puts "Input: #{len}" + + arr.permutation(len).to_a.each do |suba| + + res = 0 + + res2 = 0 + + success = 0 + + (0..len-1).each do |x| + + res = suba[x] % (x+1); + + res2 = (x+1) % suba[x]; + + if ((res == 0) || (res2 == 0) ) + + success += 1; + + end + + if (success == len) + + puts("\[#{suba}\] is cute!"); + + end + + end + + end + + puts " " + +end + + + +for arg in ARGV + + #puts arg + + if (( arg.to_i < 1) || (arg.to_i > 15)) + + puts "Error: supplied arg = #{arg}. arg must be greater than 0 and less than 16"; + + exit; + + end + + main(arg) + +end + + + +=begin + +SAMPLE OUTPUT + + + +ruby .\CuteList.rb 2 3 4 + +Input: 2 + +[[1, 2]] is cute! + +[[2, 1]] is cute! + + + +Input: 3 + +[[1, 2, 3]] is cute! + +[[2, 1, 3]] is cute! + +[[3, 2, 1]] is cute! + + + +Input: 4 + +[[1, 2, 3, 4]] is cute! + +[[1, 4, 3, 2]] is cute! + +[[2, 1, 3, 4]] is cute! + +[[2, 4, 3, 1]] is cute! + +[[3, 2, 1, 4]] is cute! + +[[3, 4, 1, 2]] is cute! + +[[4, 1, 3, 2]] is cute! + +[[4, 2, 3, 1]] is cute! + +=end diff --git a/stats/pwc-current.json b/stats/pwc-current.json index f3eed37bba..d30901b2ef 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,48 +1,175 @@ { - "chart" : { - "type" : "column" + "tooltip" : { + "followPointer" : 1, + "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/>" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "series" : [ + { + "data" : [ + { + "y" : 2, + "drilldown" : "E. Choroba", + "name" : "E. Choroba" + }, + { + "name" : "Feng Chang", + "drilldown" : "Feng Chang", + "y" : 2 + }, + { + "name" : "Flavio Poletti", + "drilldown" : "Flavio Poletti", + "y" : 6 + }, + { + "drilldown" : "Humberto Massa", + "name" : "Humberto Massa", + "y" : 2 + }, + { + "y" : 3, + "name" : "James Smith", + "drilldown" : "James Smith" + }, + { + "y" : 2, + "drilldown" : "Jorg Sommrey", + "name" : "Jorg Sommrey" + }, + { + "y" : 5, + "name" : "Laurent Rosenfeld", + "drilldown" : "Laurent Rosenfeld" + }, + { + "name" : "Luca Ferrari", + "drilldown" : "Luca Ferrari", + "y" : 8 + }, + { + "y" : 2, + "drilldown" : "Mark Anderson", + "name" : "Mark Anderson" + }, + { + "drilldown" : "Marton Polgar", + "name" : "Marton Polgar", + "y" : 2 + }, + { + "drilldown" : "Mohammad S Anwar", + "name" : "Mohammad S Anwar", + "y" : 2 + }, + { + "drilldown" : "Niels van Dijke", + "name" : "Niels van Dijke", + "y" : 2 + }, + { + "name" : "Peter Campbell Smith", + "drilldown" : "Peter Campbell Smith", + "y" : 3 + }, + { + "name" : "Robbie Hatley", + "drilldown" : "Robbie Hatley", + "y" : 2 + }, + { + "name" : "Robert DiCicco", + "drilldown" : "Robert DiCicco", + "y" : 4 + }, + { + "drilldown" : "Roger Bell_West", + "name" : "Roger Bell_West", + "y" : 4 + }, + { + "y" : 2, + "drilldown" : "Simon Proctor", + "name" : "Simon Proctor" + }, + { + "drilldown" : "Stephen G. Lynn", + "name" : "Stephen G. Lynn", + "y" : 5 + }, + { + "y" : 2, + "drilldown" : "Tim Potapov", + "name" : "Tim Potapov" + }, + { + "y" : 4, + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke" + }, + { + "drilldown" : "W. Luis Mochan", + "name" : "W. Luis Mochan", + "y" : 3 + } + ], + "name" : "The Weekly Challenge - 191", + "colorByPoint" : 1 } - }, + ], "xAxis" : { "type" : "category" }, - "tooltip" : { - "followPointer" : 1, - "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>", - "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>" + "legend" : { + "enabled" : 0 }, "subtitle" : { - "text" : "[Champions: 21] Last updated at 2022-11-19 10:27:32 GMT" + "text" : "[Champions: 21] Last updated at 2022-11-19 11:00:55 GMT" + }, + "chart" : { + "type" : "column" + }, + "title" : { + "text" : "The Weekly Challenge - 191" + }, + "plotOptions" : { + "series" : { + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + }, + "borderWidth" : 0 + } + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "drilldown" : { "series" : [ { + "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] ], - "id" : "E. Choroba", - "name" : "E. Choroba" + "id" : "E. Choroba" }, { - "id" : "Feng Chang", + "name" : "Feng Chang", "data" : [ [ "Raku", 2 ] ], - "name" : "Feng Chang" + "id" : "Feng Chang" }, { "name" : "Flavio Poletti", - "id" : "Flavio Poletti", "data" : [ [ "Perl", @@ -56,19 +183,21 @@ "Blog", 2 ] - ] + ], + "id" : "Flavio Poletti" }, { "name" : "Humberto Massa", + "id" : "Humberto Massa", "data" : [ [ "Raku", 2 ] - ], - "id" : "Humberto Massa" + ] }, { + "name" : "James Smith", "id" : "James Smith", "data" : [ [ @@ -79,8 +208,7 @@ "Blog", 1 ] - ], - "name" : "James Smith" + ] }, { "name" : "Jorg Sommrey", @@ -94,6 +222,7 @@ }, { "name" : "Laurent Rosenfeld", + "id" : "Laurent Rosenfeld", "data" : [ [ "Perl", @@ -107,12 +236,9 @@ "Blog", 1 ] - ], - "id" : "Laurent Rosenfeld" + ] }, { - "name" : "Luca Ferrari", - "id" : "Luca Ferrari", "data" : [ [ "Raku", @@ -122,29 +248,32 @@ "Blog", 6 ] - ] + ], + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" }, { "name" : "Mark Anderson", + "id" : "Mark Anderson", "data" : [ [ "Raku", 2 ] - ], - "id" : "Mark Anderson" + ] }, { + "name" : "Marton Polgar", "data" : [ [ "Raku", 2 ] ], - "id" : "Marton Polgar", - "name" : "Marton Polgar" + "id" : "Marton Polgar" }, { + "id" : "Mohammad S Anwar", "data" : [ [ "Perl", @@ -155,20 +284,20 @@ 1 ] ], - "id" : "Mohammad S Anwar", "name" : "Mohammad S Anwar" }, { - "name" : "Niels van Dijke", + "id" : "Niels van Dijke", "data" : [ [ "Perl", 2 ] ], - "id" : "Niels van Dijke" + "name" : "Niels van Dijke" }, { + "id" : "Peter Campbell Smith", "data" : [ [ "Perl", @@ -179,32 +308,31 @@ 1 ] ], - "id" : "Peter Campbell Smith", "name" : "Peter Campbell Smith" }, { + "name" : "Robbie Hatley", "id" : "Robbie Hatley", "data" : [ [ "Perl", 2 ] - ], - "name" : "Robbie Hatley" + ] }, { "name" : "Robert DiCicco", + "id" : "Robert DiCicco", "data" : [ [ "Perl", - 1 + 2 ], [ "Raku", - 1 + 2 ] - ], - "id" : "Robert DiCicco" + ] }, { "name" : "Roger Bell_West", @@ -221,17 +349,16 @@ "id" : "Roger Bell_West" }, { - "name" : "Simon Proctor", + "id" : "Simon Proctor", "data" : [ [ "Raku", 2 ] ], - "id" : "Simon Proctor" + "name" : "Simon Proctor" }, { - "name" : "Stephen G. Lynn", "id" : "Stephen G. Lynn", "data" : [ [ @@ -246,17 +373,18 @@ "Blog", 1 ] - ] + ], + "name" : "Stephen G. Lynn" }, { - "name" : "Tim Potapov", "data" : [ [ "Perl", 2 ] ], - "id" : "Tim Potapov" + "id" : "Tim Potapov", + "name" : "Tim Potapov" }, { "id" : "Ulrich Rieke", @@ -273,7 +401,6 @@ "name" : "Ulrich Rieke" }, { - "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -284,136 +411,9 @@ 1 ] ], + "id" : "W. Luis Mochan", "name" : "W. Luis Mochan" } ] - }, - "legend" : { - "enabled" : 0 - }, - "title" : { - "text" : "The Weekly Challenge - 191" - }, - "series" : [ - { - "name" : "The Weekly Challenge - 191", - "data" : [ - { - "drilldown" : "E. Choroba", - "y" : 2, - "name" : "E. Choroba" - }, - { - "y" : 2, - "name" : "Feng Chang", - "drilldown" : "Feng Chang" - }, - { - "drilldown" : "Flavio Poletti", - "name" : "Flavio Poletti", - "y" : 6 - }, - { - "y" : 2, - "name" : "Humberto Massa", - "drilldown" : "Humberto Massa" - }, - { - "drilldown" : "James Smith", - "y" : 3, - "name" : "James Smith" - }, - { - "drilldown" : "Jorg Sommrey", - "name" : "Jorg Sommrey", - "y" : 2 - }, - { - "y" : 5, - "name" : "Laurent Rosenfeld", - "drilldown" : "Laurent Rosenfeld" - }, - { - "y" : 8, - "name" : "Luca Ferrari", - "drilldown" : "Luca Ferrari" - }, - { - "name" : "Mark Anderson", - "y" : 2, - "drilldown" : "Mark Anderson" - }, - { - "name" : "Marton Polgar", - "y" : 2, - "drilldown" : "Marton Polgar" - }, - { - "drilldown" : "Mohammad S Anwar", - "y" : 2, - "name" : "Mohammad S Anwar" - }, - { - "drilldown" : "Niels van Dijke", - "y" : 2, - "name" : "Niels van Dijke" - }, - { - "drilldown" : "Peter Campbell Smith", - "y" : 3, - "name" : "Peter Campbell Smith" - }, - { - "name" : "Robbie Hatley", - "y" : 2, - "drilldown" : "Robbie Hatley" - }, - { - "drilldown" : "Robert DiCicco", - "name" : "Robert DiCicco", - "y" : 2 - }, - { - "drilldown" : "Roger Bell_West", - "y" : 4, - "name" : "Roger Bell_West" - }, - { - "y" : 2, - "name" : "Simon Proctor", - "drilldown" : "Simon Proctor" - }, - { - "drilldown" : "Stephen G. Lynn", - "y" : 5, - "name" : "Stephen G. Lynn" - }, - { - "drilldown" : "Tim Potapov", - "y" : 2, - "name" : "Tim Potapov" - }, - { - "drilldown" : "Ulrich Rieke", - "y" : 4, - "name" : "Ulrich Rieke" - }, |
