aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-24 13:16:54 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-02-24 13:16:54 +0000
commitb794f36b29be553e1b6dc1e790c5d0bf331a9bc3 (patch)
tree5f189399ad636389ada65632e0dcfff644bf89ef
parent09ef9e42063fa70127c88b6c6991a0ef6697a880 (diff)
downloadperlweeklychallenge-club-b794f36b29be553e1b6dc1e790c5d0bf331a9bc3.tar.gz
perlweeklychallenge-club-b794f36b29be553e1b6dc1e790c5d0bf331a9bc3.tar.bz2
perlweeklychallenge-club-b794f36b29be553e1b6dc1e790c5d0bf331a9bc3.zip
- Added solutions by Wanderdoc.
-rw-r--r--challenge-049/wanderdoc/perl/ch-1.pl59
-rw-r--r--challenge-049/wanderdoc/perl/ch-2.pl164
-rw-r--r--stats/pwc-current.json89
-rw-r--r--stats/pwc-language-breakdown-summary.json50
-rw-r--r--stats/pwc-language-breakdown.json372
-rw-r--r--stats/pwc-leaders.json776
-rw-r--r--stats/pwc-summary-1-30.json100
-rw-r--r--stats/pwc-summary-121-150.json42
-rw-r--r--stats/pwc-summary-31-60.json38
-rw-r--r--stats/pwc-summary-61-90.json120
-rw-r--r--stats/pwc-summary-91-120.json102
-rw-r--r--stats/pwc-summary.json346
12 files changed, 1248 insertions, 1010 deletions
diff --git a/challenge-049/wanderdoc/perl/ch-1.pl b/challenge-049/wanderdoc/perl/ch-1.pl
new file mode 100644
index 0000000000..c80a6ee6ae
--- /dev/null
+++ b/challenge-049/wanderdoc/perl/ch-1.pl
@@ -0,0 +1,59 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+Write a script to accept a positive number as command line argument and print the smallest multiple of the given number consists of digits 0 and 1.
+For example: For given number 55, the smallest multiple is 110 consisting of digits 0 and 1.
+=cut
+
+
+
+
+
+
+=notes
+For now: Solution with brute force. Works, however there are several cases where it takes too long.
+I will try to implement the pidgeonhole algorithmus seen here: https://math.stackexchange.com/questions/83932 .
+=cut
+
+
+use Math::BigInt;
+Math::BigInt->accuracy(30);
+use Time::HiRes qw[ time ];
+
+
+
+my $NUM = shift or die "Which number?\n";
+my $start = time;
+
+my $FLAG_2_5 = ($NUM % 2 == 0 or $NUM % 5 == 0) ? 1 : 0;
+
+for my $i (1 .. 1_000_000_000)
+{
+ my $multiple = sprintf("%b", $i);
+ if ( $FLAG_2_5 == 1 and substr($multiple, -1, 1) eq '1' ) {next; }
+
+ if ( length($multiple) > 17 )
+ {
+
+
+ my $x = Math::BigInt->new($multiple);
+ my $modulo = $x->bmod($NUM);
+ if (0 == $modulo)
+ {
+ print $multiple, $/; last;
+ }
+ }
+
+
+ else
+ {
+ if ( 0 == $multiple % $NUM )
+ {
+ print $multiple, $/; last;
+ }
+ }
+}
+
+print "Used time: ", time() - $start, $/; \ No newline at end of file
diff --git a/challenge-049/wanderdoc/perl/ch-2.pl b/challenge-049/wanderdoc/perl/ch-2.pl
new file mode 100644
index 0000000000..5f9c978117
--- /dev/null
+++ b/challenge-049/wanderdoc/perl/ch-2.pl
@@ -0,0 +1,164 @@
+#!perl
+use strict;
+use warnings FATAL => qw(all);
+
+=prompt
+Write a script to demonstrate LRU Cache feature. It should support operations get and set. Accept the capacity of the LRU Cache as command line argument.
+ Definition of LRU: An access to an item is defined as a get or a set operation of the item. “Least recently used” item is the one with the oldest access time.
+=cut
+
+
+
+
+
+
+
+
+package LRU
+{
+ use Scalar::Util qw(refaddr looks_like_number);
+ use Carp;
+ my (%DATA, %MAP, %CAPACITY);
+
+ sub new
+ {
+ my ($class, $capacity) = @_;
+
+ confess "Capacity must be a positive integer!$/"
+ unless ( looks_like_number($capacity)
+ and $capacity > 0
+ and int($capacity) == $capacity);
+
+ my $ref = bless \do{my $dummy}, $class;
+ $CAPACITY{refaddr $ref} = $capacity;
+
+ return $ref;
+ }
+
+
+
+
+ sub get_capacity
+ {
+ my $self = shift;
+
+ return $CAPACITY{refaddr $self};
+ }
+
+
+
+ sub set
+ {
+ my ($self, $key, $value) = @_;
+ push @{ $DATA{refaddr $self} }, {$key => $value};
+ while ( scalar @{ $DATA{refaddr $self} } > $CAPACITY{refaddr $self} )
+ {
+ shift @{ $DATA{refaddr $self} };
+ }
+
+ $self->_update_map;
+ }
+
+
+ sub get
+ {
+ my ($self, $key) = @_;
+ $self->_update_map;
+
+ return -1 if not exists $MAP{refaddr $self}{$key};
+
+ my $idx = $MAP{refaddr $self}{$key};
+ my $value = $DATA{refaddr $self}[$idx]->{$key};
+ my $last = splice( @{$DATA{refaddr $self}}, $idx, 1);
+ push @{$DATA{refaddr $self}}, $last;
+ $self->_update_map;
+ return $value;
+ }
+
+ sub _update_map
+ {
+ my $self = shift;
+ %{$MAP{refaddr $self}} =
+ map { my ($k) = keys %{$DATA{refaddr $self}[$_]}; $k => $_;}
+ 0 .. $#{ $DATA{refaddr $self} };
+ }
+
+ sub print_cache
+ {
+ my $self = shift;
+
+ my @cache_stringified =
+ map { my ($k, $v) = each %{$DATA{refaddr $self}[$_]};
+ qq["<${k}"=>${v}>]; }
+ 0 .. $#{ $DATA{refaddr $self} };
+
+ print "least recently used ",
+ join(" ", @cache_stringified), " most recently used", $/;
+
+ }
+
+ sub DESTROY
+ {
+ my $self = shift;
+ delete $DATA{refaddr $self};
+
+ delete $CAPACITY{refaddr $self};
+ delete $MAP{refaddr $self};
+ }
+1;
+}
+
+
+
+
+
+package main
+{
+ use Getopt::Std;
+
+ my %options=();
+ getopts("c:", \%options);
+ die "-c <capacity as integer>\n" unless defined $options{c};
+
+ my $cache = LRU->new($options{c});
+
+ print "DEBUG: Cache capacity: ", $cache->get_capacity, $/;
+
+ $cache->set(1, 3);
+ $cache->set(2, 5);
+ $cache->set(3, 7);
+
+
+ print qq[$/After first filling ... $/];
+ $cache->print_cache();
+
+ print qq[$/Getting "2" ... ];
+ print $cache->get(2), $/;
+
+
+ print qq[$/After getting "2" ... $/];
+ $cache->print_cache();
+
+ print qq[$/Getting "1" ... ];
+ print $cache->get(1), $/;
+
+ print qq[$/After getting "1" ... $/];
+ $cache->print_cache();
+
+ print qq[$/Getting "4" ... ];
+ print $cache->get(4), $/;
+
+ print qq[$/After getting "4" ... $/];
+ $cache->print_cache();
+
+ $cache->set(4, 9);
+
+ print qq[$/After setting "4" ... $/];
+ $cache->print_cache();
+
+ print qq[$/Getting "3" ... ];
+ print $cache->get(3), $/;
+
+ print qq[$/After getting "3" ... $/];
+ $cache->print_cache();
+}
diff --git a/stats/pwc-current.json b/stats/pwc-current.json
index 22b7858fbd..6f8058909f 100644
--- a/stats/pwc-current.json
+++ b/stats/pwc-current.json
@@ -1,32 +1,10 @@
{
- "title" : {
- "text" : "Perl Weekly Challenge - 049"
- },
- "tooltip" : {
- "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/>",
- "followPointer" : 1
- },
- "legend" : {
- "enabled" : 0
- },
- "plotOptions" : {
- "series" : {
- "dataLabels" : {
- "format" : "{point.y}",
- "enabled" : 1
- },
- "borderWidth" : 0
- }
- },
"series" : [
{
- "name" : "Perl Weekly Challenge - 049",
- "colorByPoint" : 1,
"data" : [
{
- "drilldown" : "Luca Ferrari",
"y" : 4,
+ "drilldown" : "Luca Ferrari",
"name" : "Luca Ferrari"
},
{
@@ -35,23 +13,29 @@
"name" : "Peter Scott"
},
{
- "name" : "Roger Bell West",
"drilldown" : "Roger Bell West",
+ "name" : "Roger Bell West",
"y" : 4
},
{
- "name" : "Simon Proctor",
"drilldown" : "Simon Proctor",
+ "name" : "Simon Proctor",
"y" : 2
+ },
+ {
+ "y" : 2,
+ "drilldown" : "Wanderdoc",
+ "name" : "Wanderdoc"
}
- ]
+ ],
+ "name" : "Perl Weekly Challenge - 049",
+ "colorByPoint" : 1
}
],
"drilldown" : {
"series" : [
{
"name" : "Luca Ferrari",
- "id" : "Luca Ferrari",
"data" : [
[
"Raku",
@@ -61,20 +45,20 @@
"Blog",
2
]
- ]
+ ],
+ "id" : "Luca Ferrari"
},
{
- "name" : "Peter Scott",
"id" : "Peter Scott",
"data" : [
[
"Perl",
1
]
- ]
+ ],
+ "name" : "Peter Scott"
},
{
- "name" : "Roger Bell West",
"id" : "Roger Bell West",
"data" : [
[
@@ -85,23 +69,31 @@
"Raku",
2
]
- ]
+ ],
+ "name" : "Roger Bell West"
},
{
- "id" : "Simon Proctor",
"name" : "Simon Proctor",
+ "id" : "Simon Proctor",
"data" : [
[
"Raku",
2
]
]
+ },
+ {
+ "data" : [
+ [
+ "Perl",
+ 2
+ ]
+ ],
+ "id" : "Wanderdoc",
+ "name" : "Wanderdoc"
}
]
},
- "xAxis" : {
- "type" : "category"
- },
"chart" : {
"type" : "column"
},
@@ -110,7 +102,30 @@
"text" : "Total Solutions"
}
},
+ "title" : {
+ "text" : "Perl Weekly Challenge - 049"
+ },
+ "plotOptions" : {
+ "series" : {
+ "dataLabels" : {
+ "format" : "{point.y}",
+ "enabled" : 1
+ },
+ "borderWidth" : 0
+ }
+ },
+ "tooltip" : {
+ "pointFormat" : "<span style='color:{point.color}'>{point.name}</span>: <b>{point.y:f}</b><br/>",
+ "followPointer" : 1,
+ "headerFormat" : "<span style='font-size:11px'>{series.name}</span><br/>"
+ },
+ "xAxis" : {
+ "type" : "category"
+ },
"subtitle" : {
- "text" : "[Champions: 4] Last updated at 2020-02-24 12:57:12 GMT"
+ "text" : "[Champions: 5] Last updated at 2020-02-24 13:16:34 GMT"
+ },
+ "legend" : {
+ "enabled" : 0
}
}
diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json
index dbd5ee1ea9..c7f8dbd748 100644
--- a/stats/pwc-language-breakdown-summary.json
+++ b/stats/pwc-language-breakdown-summary.json
@@ -1,12 +1,18 @@
{
+ "tooltip" : {
+ "pointFormat" : "<b>{point.y:.0f}</b>"
+ },
"title" : {
"text" : "Perl Weekly Challenge Contributions [2019 - 2020]"
},
- "tooltip" : {
- "pointFormat" : "<b>{point.y:.0f}</b>"
+ "yAxis" : {
+ "min" : 0,
+ "title" : {
+ "text" : null
+ }
},
- "legend" : {
- "enabled" : "false"
+ "chart" : {
+ "type" : "column"
},
"series" : [
{
@@ -17,7 +23,7 @@
],
[
"Perl",
- 2004
+ 2006
],
[
"Raku",
@@ -25,39 +31,33 @@
]
],
"dataLabels" : {
- "rotation" : -90,
"enabled" : "true",
"align" : "right",
- "style" : {
- "fontFamily" : "Verdana, sans-serif",
- "fontSize" : "13px"
- },
"color" : "#FFFFFF",
"format" : "{point.y:.0f}",
- "y" : 10
+ "rotation" : -90,
+ "y" : 10,
+ "style" : {
+ "fontSize" : "13px",
+ "fontFamily" : "Verdana, sans-serif"
+ }
},
"name" : "Contributions"
}
],
+ "subtitle" : {
+ "text" : "Last updated at 2020-02-24 13:16:34 GMT"
+ },
+ "legend" : {
+ "enabled" : "false"
+ },
"xAxis" : {
+ "type" : "category",
"labels" : {
"style" : {
"fontFamily" : "Verdana, sans-serif",
"fontSize" : "13px"
}
- },
- "type" : "category"
- },
- "yAxis" : {
- "title" : {
- "text" : null
- },
- "min" : 0
- },
- "chart" : {
- "type" : "column"
- },
- "subtitle" : {
- "text" : "Last updated at 2020-02-24 12:57:12 GMT"
+ }
}
}
diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json
index afb5773e9a..f3d96a1c5e 100644
--- a/stats/pwc-language-breakdown.json
+++ b/stats/pwc-language-breakdown.json
@@ -1,22 +1,21 @@
{
"subtitle" : {
- "text" : "Click the columns to drilldown the language breakdown. Last updated at 2020-02-24 12:57:12 GMT"
+ "text" : "Click the columns to drilldown the language breakdown. Last updated at 2020-02-24 13:16:34 GMT"
},
- "chart" : {
- "type" : "column"
- },
- "yAxis" : {
- "title" : {
- "text" : "Total Solutions"
- }
+ "legend" : {
+ "enabled" : "false"
},
"xAxis" : {
"type" : "category"
},
+ "tooltip" : {
+ "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"
+ },
"drilldown" : {
"series" : [
{
- "name" : "001",
"id" : "001",
"data" : [
[
@@ -31,9 +30,11 @@
"Blog",
11
]
- ]
+ ],
+ "name" : "001"
},
{
+ "name" : "002",
"data" : [
[
"Perl",
@@ -48,12 +49,10 @@
10
]
],
- "id" : "002",
- "name" : "002"
+ "id" : "002"
},
{
"id" : "003",
- "name" : "003",
"data" : [
[
"Perl",
@@ -67,10 +66,10 @@
"Blog",
9
]
- ]
+ ],
+ "name" : "003"
},
{
- "name" : "004",
"id" : "004",
"data" : [
[
@@ -85,7 +84,8 @@
"Blog",
10
]
- ]
+ ],
+ "name" : "004"
},
{
"data" : [
@@ -102,10 +102,11 @@
12
]
],
- "name" : "005",
- "id" : "005"
+ "id" : "005",
+ "name" : "005"
},
{
+ "id" : "006",
"data" : [
[
"Perl",
@@ -120,10 +121,10 @@
7
]
],
- "id" : "006",
"name" : "006"
},
{
+ "name" : "007",
"data" : [
[
"Perl",
@@ -138,10 +139,10 @@
10
]
],
- "id" : "007",
- "name" : "007"
+ "id" : "007"
},
{
+ "name" : "008",
"data" : [
[
"Perl",
@@ -156,12 +157,10 @@
12
]
],
- "name" : "008",
"id" : "008"
},
{
"name" : "009",
- "id" : "009",
"data" : [
[
"Perl",
@@ -175,11 +174,12 @@
"Blog",
13
]
- ]
+ ],
+ "id" : "009"
},
{
- "id" : "010",
"name" : "010",
+ "id" : "010",
"data" : [
[
"Perl",
@@ -196,6 +196,7 @@
]
},
{
+ "name" : "011",
"data" : [
[
"Perl",
@@ -210,11 +211,9 @@
10
]
],
- "name" : "011",
"id" : "011"
},
{
- "name" : "012",
"id" : "012",
"data" : [
[
@@ -229,11 +228,11 @@
"Blog",
11
]
- ]
+ ],
+ "name" : "012"
},
{
"id" : "013",
- "name" : "013",
"data" : [
[
"Perl",
@@ -247,9 +246,11 @@
"Blog",
13
]
- ]
+ ],
+ "name" : "013"
},
{
+ "name" : "014",
"data" : [
[
"Perl",
@@ -264,10 +265,11 @@
15
]
],
- "id" : "014",
- "name" : "014"
+ "id" : "014"
},
{
+ "name" : "015",
+ "id" : "015",
"data" : [
[
"Perl",
@@ -281,12 +283,9 @@
"Blog",
15
]
- ],
- "name" : "015",
- "id" : "015"
+ ]
},
{
- "name" : "016",
"id" : "016",
"data" : [
[
@@ -301,9 +300,12 @@
"Blog",
12
]
- ]
+ ],
+ "name" : "016"
},
{
+ "name" : "017",
+ "id" : "017",
"data" : [
[
"Perl",
@@ -317,9 +319,7 @@
"Blog",
12
]
- ],
- "id" : "017",
- "name" : "017"
+ ]
},
{
"name" : "018",
@@ -340,6 +340,7 @@
]
},
{
+ "name" : "019",
"data" : [
[
"Perl",
@@ -354,12 +355,11 @@
13
]
],
- "name" : "019",
"id" : "019"
},
{
- "id" : "020",
"name" : "020",
+ "id" : "020",
"data" : [
[
"Perl",
@@ -394,6 +394,7 @@
]
},
{
+ "id" : "022",
"data" : [
[
"Perl",
@@ -408,11 +409,9 @@
10
]
],
- "id" : "022",
"name" : "022"
},
{
- "name" : "023",
"id" : "023",
"data" : [
[
@@ -427,11 +426,11 @@
"Blog",
12
]
- ]
+ ],
+ "name" : "023"
},
{
"name" : "024",
- "id" : "024",
"data" : [
[
"Perl",
@@ -445,10 +444,10 @@
"Blog",
11
]
- ]
+ ],
+ "id" : "024"
},
{
- "id" : "025",
"name" : "025",
"data" : [
[
@@ -463,11 +462,11 @@
"Blog",
12
]
- ]
+ ],
+ "id" : "025"
},
{
"id" : "026",
- "name" : "026",
"data" : [
[
"Perl",
@@ -481,9 +480,12 @@
"Blog",
10
]
- ]
+ ],
+ "name" : "026"
},
{
+ "name" : "027",
+ "id" : "027",
"data" : [
[
"Perl",
@@ -497,11 +499,10 @@
"Blog",
9
]
- ],
- "id" : "027",
- "name" : "027"
+ ]
},
{
+ "name" : "028",
"data" : [
[
"Perl",
@@ -516,10 +517,11 @@
9
]
],
- "id" : "028",
- "name" : "028"
+ "id" : "028"
},
{
+ "name" : "029",
+ "id" : "029",
"data" : [
[
"Perl",
@@ -533,13 +535,10 @@
"Blog",
12
]
- ],
- "name" : "029",
- "id" : "029"
+ ]
},
{
"name" : "030",
- "id" : "030",
"data" : [
[
"Perl",
@@ -553,7 +552,8 @@
"Blog",
10
]
- ]
+ ],
+ "id" : "030"
},
{
"data" : [
@@ -592,8 +592,6 @@
]
},
{
- "name" : "033",
- "id" : "033",
"data" : [
[
"Perl",
@@ -607,9 +605,12 @@
"Blog",
10
]
- ]
+ ],
+ "id" : "033",
+ "name" : "033"
},
{
+ "name" : "034",
"data" : [
[
"Perl",
@@ -624,11 +625,9 @@
11
]
],
- "name" : "034",
"id" : "034"
},
{
- "name" : "035",
"id" : "035",
"data" : [
[
@@ -643,10 +642,10 @@
"Blog",
9
]
- ]
+ ],
+ "name" : "035"
},
{
- "id" : "036",
"name" : "036",
"data" : [
[
@@ -661,9 +660,11 @@
"Blog",
10
]
- ]
+ ],
+ "id" : "036"
},
{
+ "id" : "037",
"data" : [
[
"Perl",
@@ -678,10 +679,10 @@
9
]
],
- "name" : "037",
- "id" : "037"
+ "name" : "037"
},
{
+ "id" : "038",
"data" : [
[
"Perl",
@@ -696,10 +697,10 @@
11
]
],
- "id" : "038",
"name" : "038"
},
{
+ "name" : "039",
"data" : [
[
"Perl",
@@ -714,8 +715,7 @@
12
]
],
- "id" : "039",
- "name" : "039"
+ "id" : "039"
},
{
"data" : [
@@ -732,10 +732,12 @@
9
]
],
- "name" : "040",
- "id" : "040"
+ "id" : "040",
+ "name" : "040"
},
{
+ "name" : "041",
+ "id" : "041",
"data" : [
[
"Perl",
@@ -749,11 +751,10 @@
"Blog",
8
]
- ],
- "id" : "041",
- "name" : "041"
+ ]
},
{
+ "name" : "042",
"data" : [
[
"Perl",
@@ -768,10 +769,11 @@
11
]
],
- "name" : "042",
"id" : "042"
},
{
+ "name" : "043",
+ "id" : "043",
"data" : [
[
"Perl",
@@ -785,11 +787,10 @@
"Blog",
10
]
- ],
- "name" : "043",
- "id" : "043"
+ ]
},
{
+ "id" : "044",
"data" : [
[
"Perl",
@@ -804,12 +805,9 @@
10
]
],
- "name" : "044",
- "id" : "044"
+ "name" : "044"
},
{
- "name" : "045",
- "id" : "045",
"data" : [
[
"Perl",
@@ -823,10 +821,11 @@
"Blog",
11
]
- ]
+ ],
+ "id" : "045",
+ "name" : "045"
},
{
- "name" : "046",
"id" : "046",
"data" : [
[
@@ -841,7 +840,8 @@
"Blog",
9
]
- ]
+ ],
+ "name" : "046"
},
{
"name" : "047",
@@ -863,7 +863,6 @@
},
{
"id" : "048",
- "name" : "048",
"data" : [
[
"Perl",
@@ -877,15 +876,15 @@
"Blog",
11
]
- ]
+ ],
+ "name" : "048"
},
{
"id" : "049",
- "name" : "049",
"data" : [
[
"Perl",
- 3
+ 5
],
[
"Raku",
@@ -895,64 +894,63 @@
"Blog",
2
]
- ]
+ ],
+ "name" : "049"
}
]
},
"series" : [
{
- "name" : "Perl Weekly Challenge Languages",
- "colorByPoint" : "true",
"data" : [
{
- "name" : "#001",
+ "y" : 140,
"drilldown" : "001",
- "y" : 140
+ "name" : "#001"
},
{
- "name" : "#002",
+ "y" : 109,
"drilldown" : "002",
- "y" : 109
+ "name" : "#002"
},
{
+ "name" : "#003",
"drilldown" : "003",
- "y" : 71,
- "name" : "#003"
+ "y" : 71
},
{
- "drilldown" : "004",
"y" : 91,
- "name" : "#004"
+ "name" : "#004",
+ "drilldown" : "004"
},
{
+ "name" : "#005",
"drilldown" : "005",
- "y" : 71,
- "name" : "#005"
+ "y" : 71
},
{
- "name" : "#006",
"y" : 48,
- "drilldown" : "006"
+ "drilldown" : "006",
+ "name" : "#006"
},
{
- "y" : 56,
+ "name" : "#007",
"drilldown" : "007",
- "name" : "#007"
+ "y" : 56