diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-10 05:22:50 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2021-11-10 05:22:50 +0000 |
| commit | 59ef64e03dc6f972b730247262d2215bfa526085 (patch) | |
| tree | d43aa19df885d21cda026dc4d19a4b36a04d7ab5 | |
| parent | f12b838e791bbf7fb90d962063a3c93ea0a15056 (diff) | |
| download | perlweeklychallenge-club-59ef64e03dc6f972b730247262d2215bfa526085.tar.gz perlweeklychallenge-club-59ef64e03dc6f972b730247262d2215bfa526085.tar.bz2 perlweeklychallenge-club-59ef64e03dc6f972b730247262d2215bfa526085.zip | |
- Added solutions to "Workdays" task of week 138.
| -rw-r--r-- | challenge-138/mohammad-anwar/java/theweeklychallenge/Workdays.java | 48 | ||||
| -rw-r--r-- | challenge-138/mohammad-anwar/perl/ch-1.pl | 40 | ||||
| -rw-r--r-- | challenge-138/mohammad-anwar/python/ch-1.py | 49 | ||||
| -rw-r--r-- | challenge-138/mohammad-anwar/raku/ch-1.raku | 38 | ||||
| -rw-r--r-- | challenge-138/mohammad-anwar/swift/ch-1.swift | 90 | ||||
| -rw-r--r-- | stats/pwc-current.json | 121 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown-summary.json | 76 | ||||
| -rw-r--r-- | stats/pwc-language-breakdown.json | 1886 | ||||
| -rw-r--r-- | stats/pwc-leaders.json | 382 | ||||
| -rw-r--r-- | stats/pwc-summary-1-30.json | 34 | ||||
| -rw-r--r-- | stats/pwc-summary-121-150.json | 122 | ||||
| -rw-r--r-- | stats/pwc-summary-151-180.json | 106 | ||||
| -rw-r--r-- | stats/pwc-summary-181-210.json | 44 | ||||
| -rw-r--r-- | stats/pwc-summary-211-240.json | 98 | ||||
| -rw-r--r-- | stats/pwc-summary-241-270.json | 30 | ||||
| -rw-r--r-- | stats/pwc-summary-31-60.json | 36 | ||||
| -rw-r--r-- | stats/pwc-summary-61-90.json | 100 | ||||
| -rw-r--r-- | stats/pwc-summary-91-120.json | 130 | ||||
| -rw-r--r-- | stats/pwc-summary.json | 526 |
19 files changed, 2120 insertions, 1836 deletions
diff --git a/challenge-138/mohammad-anwar/java/theweeklychallenge/Workdays.java b/challenge-138/mohammad-anwar/java/theweeklychallenge/Workdays.java new file mode 100644 index 0000000000..95924f8160 --- /dev/null +++ b/challenge-138/mohammad-anwar/java/theweeklychallenge/Workdays.java @@ -0,0 +1,48 @@ +package theweeklychallenge; + +/* + +Week 138: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-138 + +Task #1: Wrokdays + + You are given a year in 4-digits form. Write a script to calculate the total number of workdays in the given year. + +*/ + +import java.time.LocalDate; +import junit.framework.TestCase; +import static junit.framework.Assert.*; + +public class Workdays extends TestCase { + + public static void main(String[] args) { + junit.textui.TestRunner.run(theweeklychallenge.Workdays.class); + } + + public void testWorkdays() { + assertEquals(workdays(2021), 261); + assertEquals(workdays(2020), 262); + } + + public static int workdays(int year) { + int d = 1; + int m = 1; + int y = year; + + int workdays = 0; + while (year == y) { + LocalDate date = LocalDate.of(y, m, d); + if (date.getDayOfWeek().getValue() < 6) workdays += 1; + + date = date.plusDays(1); + y = date.getYear(); + m = date.getMonthValue(); + d = date.getDayOfMonth(); + } + + return workdays; + } +} diff --git a/challenge-138/mohammad-anwar/perl/ch-1.pl b/challenge-138/mohammad-anwar/perl/ch-1.pl new file mode 100644 index 0000000000..1634f4e555 --- /dev/null +++ b/challenge-138/mohammad-anwar/perl/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl + +=head1 + +Week 138: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-138 + +Task #1: Workdays + + You are given a year in 4-digits form. Write a script to calculate the total number of workdays in the given year. + +=cut + +use strict; +use warnings; + +use Test::More; +use Date::Calc qw(Day_of_Week Add_Delta_Days); + +is(workdays(2021), 261, 'Example 1'); +is(workdays(2020), 262, 'Example 2'); + +done_testing; + +sub workdays { + my ($year) = @_; + + my $d = 1; + my $m = 1; + my $y = $year; + + my $workdays = 0; + while ($year == $y) { + (Day_of_Week($y, $m, $d) < 6) and $workdays++; + ($y, $m, $d) = Add_Delta_Days($y, $m, $d, 1); + } + + return $workdays; +} diff --git a/challenge-138/mohammad-anwar/python/ch-1.py b/challenge-138/mohammad-anwar/python/ch-1.py new file mode 100644 index 0000000000..c3aa068659 --- /dev/null +++ b/challenge-138/mohammad-anwar/python/ch-1.py @@ -0,0 +1,49 @@ +#!/usr/bin/python3 + +''' + +Week 138: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-138 + +Task #1: Workdays + + You are given a year in 4-digits form. Write a script to calculate the total number of workdays in the given year. + +''' + +import unittest +from datetime import datetime +from datetime import timedelta + +def workdays(year): + d = 1 + m = 1 + y = year + + workdays = 0 + while year == y: + + date = datetime(y, m, d) + if date.weekday() < 5: workdays += 1 + date = date + timedelta(days = 1) + + y = date.year + m = date.month + d = date.day + + return workdays + +# +# +# Unit test class + +class TestWorkdays(unittest.TestCase): + + def test_example_1(self): + self.assertEqual(workdays(2021), 261, 'Example 1') + + def test_example_2(self): + self.assertEqual(workdays(2020), 262, 'Example 2') + +unittest.main() diff --git a/challenge-138/mohammad-anwar/raku/ch-1.raku b/challenge-138/mohammad-anwar/raku/ch-1.raku new file mode 100644 index 0000000000..f89c305c2f --- /dev/null +++ b/challenge-138/mohammad-anwar/raku/ch-1.raku @@ -0,0 +1,38 @@ +#!/usr/bin/env raku + +=begin pod + +Week 138: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-138 + +Task #1: Workdays + + You are given a year in 4-digits form. Write a script to calculate the total number of workdays in the given year. + +=end pod + +use Test; + +is workdays(2021), 261, 'Example 1'; +is workdays(2020), 262, 'Example 2'; + +done-testing; + +# +# +# METHODS + +sub workdays(Int $year where $year > 0 --> Int) { + + my Int $y = $year; + my $date = Date.new("$y-01-01"); + my $workdays = 0; + + while $year == $y { + ($date.day-of-week < 6) and $workdays++; + $date++ and $y = $date.year; + } + + return $workdays; +} diff --git a/challenge-138/mohammad-anwar/swift/ch-1.swift b/challenge-138/mohammad-anwar/swift/ch-1.swift new file mode 100644 index 0000000000..656671c5b9 --- /dev/null +++ b/challenge-138/mohammad-anwar/swift/ch-1.swift @@ -0,0 +1,90 @@ +import Foundation + +/* + +Week 138: + + https://theweeklychallenge.org/blog/perl-weekly-challenge-138 + +Task #1: Workdays + + You are given a year in 4-digits form. Write a script to calculate the total number of workdays in the given year. + +*/ + +enum ParamError: Error { + case missingYear + case invalidYear +} + +do { + let paramCount:Int = Int(CommandLine.argc) + + if paramCount <= 1 { + throw ParamError.missingYear + } + + let year:Int = Int(CommandLine.arguments[1])! + + if year >= 1 { + print(workdays(year)) + } + else { + throw ParamError.invalidYear + } +} +catch ParamError.missingYear { + print("Missing year.") +} +catch ParamError.invalidYear { + print("Invalid year.") +} +catch let error { + print(error) +} + +// +// +// Functions + +func workdays(_ year:Int) -> Int { + + var d:Int = 1 + var m:Int = 1 + var y:Int = year + + var workdays: Int = 0 + while year == y { + var date = date(y, m, d) + + if weekDay(date) < 6 { + workdays += 1 + } + + date = addDays(date, 1) + y = Calendar.current.dateComponents([.year], from: date).year! + m = Calendar.current.dateComponents([.month], from: date).month! + d = Calendar.current.dateComponents([.day], from: date).day! + } + + return workdays +} + +func date(_ year: Int, _ month: Int, _ day: Int) -> Date { + let calendar = NSCalendar(calendarIdentifier: .gregorian)! + + var dateComponents = DateComponents() + dateComponents.year = year + dateComponents.month = month + dateComponents.day = day + + return calendar.date(from: dateComponents)! +} + +func weekDay(_ date: Date) -> Int { + return Calendar.current.component(.weekday, from: date) +} + +func addDays(_ date: Date, _ days: Int) -> Date { + return Calendar.current.date(byAdding: .day, value: days, to: date)! +} diff --git a/stats/pwc-current.json b/stats/pwc-current.json index abdb8a3fef..e1a5ca2e9f 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -5,9 +5,9 @@ "name" : "The Weekly Challenge - 138", "data" : [ { - "drilldown" : "Andrew Shitov", + "name" : "Andrew Shitov", "y" : 1, - "name" : "Andrew Shitov" + "drilldown" : "Andrew Shitov" }, { "drilldown" : "Dave Jacoby", @@ -35,19 +35,24 @@ "drilldown" : "Mark Anderson" }, { + "name" : "Mohammad S Anwar", + "y" : 2, + "drilldown" : "Mohammad S Anwar" + }, + { "drilldown" : "Paulo Custodio", - "name" : "Paulo Custodio", - "y" : 2 + "y" : 2, + "name" : "Paulo Custodio" }, { - "drilldown" : "Peter Campbell Smith", "y" : 2, - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "drilldown" : "Peter Campbell Smith" }, { - "drilldown" : "Robert DiCicco", + "y" : 2, "name" : "Robert DiCicco", - "y" : 2 + "drilldown" : "Robert DiCicco" }, { "y" : 4, @@ -55,40 +60,42 @@ "drilldown" : "Roger Bell_West" }, { - "name" : "Simon Green", "y" : 3, + "name" : "Simon Green", "drilldown" : "Simon Green" }, { - "drilldown" : "Ulrich Rieke", "y" : 4, - "name" : "Ulrich Rieke" + "name" : "Ulrich Rieke", + "drilldown" : "Ulrich Rieke" }, { + "drilldown" : "W. Luis Mochan", "name" : "W. Luis Mochan", - "y" : 3, - "drilldown" : "W. Luis Mochan" + "y" : 3 } ] } ], - "title" : { - "text" : "The Weekly Challenge - 138" + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, - "legend" : { - "enabled" : 0 + "xAxis" : { + "type" : "category" }, "drilldown" : { "series" : [ { - "id" : "Andrew Shitov", - "name" : "Andrew Shitov", "data" : [ [ "Raku", 1 ] - ] + ], + "name" : "Andrew Shitov", + "id" : "Andrew Shitov" }, { "id" : "Dave Jacoby", @@ -105,17 +112,18 @@ "name" : "Dave Jacoby" }, { - "id" : "E. Choroba", - "name" : "E. Choroba", "data" : [ [ "Perl", 2 ] - ] + ], + "name" : "E. Choroba", + "id" : "E. Choroba" }, { "id" : "James Smith", + "name" : "James Smith", "data" : [ [ "Perl", @@ -125,8 +133,7 @@ "Blog", 1 ] - ], - "name" : "James Smith" + ] }, { "name" : "Luca Ferrari", @@ -143,16 +150,30 @@ "id" : "Luca Ferrari" }, { - "name" : "Mark Anderson", "data" : [ [ "Raku", 2 ] ], + "name" : "Mark Anderson", "id" : "Mark Anderson" }, { + "data" : [ + [ + "Perl", + 1 + ], + [ + "Raku", + 1 + ] + ], + "name" : "Mohammad S Anwar", + "id" : "Mohammad S Anwar" + }, + { "name" : "Paulo Custodio", "data" : [ [ @@ -163,27 +184,26 @@ "id" : "Paulo Custodio" }, { - "id" : "Peter Campbell Smith", "data" : [ [ "Perl", 2 ] ], - "name" : "Peter Campbell Smith" + "name" : "Peter Campbell Smith", + "id" : "Peter Campbell Smith" }, { - "name" : "Robert DiCicco", "data" : [ [ "Perl", 2 ] ], + "name" : "Robert DiCicco", "id" : "Robert DiCicco" }, { - "name" : "Roger Bell_West", "data" : [ [ "Perl", @@ -194,6 +214,7 @@ 2 ] ], + "name" : "Roger Bell_West", "id" : "Roger Bell_West" }, { @@ -225,6 +246,7 @@ "name" : "Ulrich Rieke" }, { + "id" : "W. Luis Mochan", "data" : [ [ "Perl", @@ -235,36 +257,33 @@ 1 ] ], - "name" : "W. Luis Mochan", - "id" : "W. Luis Mochan" + "name" : "W. Luis Mochan" } ] }, - "plotOptions" : { - "series" : { - "borderWidth" : 0, - "dataLabels" : { - "enabled" : 1, - "format" : "{point.y}" - } - } + "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: 13] Last updated at 2021-11-10 02:54:39 GMT" + "text" : "[Champions: 14] Last updated at 2021-11-10 05:21:28 GMT" }, - "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/>" + "title" : { + "text" : "The Weekly Challenge - 138" }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" + "plotOptions" : { + "series" : { + "dataLabels" : { + "format" : "{point.y}", + "enabled" : 1 + }, + "borderWidth" : 0 } }, - "xAxis" : { - "type" : "category" - }, "chart" : { "type" : "column" } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 3590e5f5c0..dae34f3e81 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -1,6 +1,34 @@ { + "xAxis" : { + "type" : "category", + "labels" : { + "style" : { + "fontSize" : "13px", + "fontFamily" : "Verdana, sans-serif" + } + } + }, + "yAxis" : { + "title" : { + "text" : null + }, + "min" : 0 + }, "series" : [ { + "name" : "Contributions", + "dataLabels" : { + "y" : 10, + "align" : "right", + "style" : { + "fontFamily" : "Verdana, sans-serif", + "fontSize" : "13px" + }, + "rotation" : -90, + "enabled" : "true", + "color" : "#FFFFFF", + "format" : "{point.y:.0f}" + }, "data" : [ [ "Blog", @@ -8,56 +36,28 @@ ], [ "Perl", - 6605 + 6606 ], [ "Raku", - 4003 + 4004 ] - ], - "name" : "Contributions", - "dataLabels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - }, - "align" : "right", - "rotation" : -90, - "enabled" : "true", - "color" : "#FFFFFF", - "format" : "{point.y:.0f}", - "y" : 10 - } + ] } ], - "legend" : { - "enabled" : "false" + "chart" : { + "type" : "column" + }, + "subtitle" : { + "text" : "Last updated at 2021-11-10 05:21:28 GMT" }, "title" : { "text" : "The Weekly Challenge Contributions [2019 - 2021]" }, - "subtitle" : { - "text" : "Last updated at 2021-11-10 02:54:39 GMT" + "legend" : { + "enabled" : "false" }, "tooltip" : { "pointFormat" : "<b>{point.y:.0f}</b>" - }, - "yAxis" : { - "min" : 0, - "title" : { - "text" : null - } - }, - "chart" : { - "type" : "column" - }, - "xAxis" : { - "type" : "category", - "labels" : { - "style" : { - "fontFamily" : "Verdana, sans-serif", - "fontSize" : "13px" - } - } } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index 6089b9081b..524c4f0e2c 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,34 +1,730 @@ { - "chart" : { - "type" : "column" - }, - "xAxis" : { - "type" : "category" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } + "legend" : { + "enabled" : "false" }, "tooltip" : { + "followPointer" : "true", "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" - }, - "subtitle" : { - "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-11-10 02:54:39 GMT" + "pointFormat" : "<span style=\"color:{point.color}\">Challenge {point.name}</span>: <b>{point.y:f}</b><br/>" }, "plotOptions" : { "series" : { - "borderWidth" : 0, "dataLabels" : { "format" : "{point.y}", "enabled" : 1 - } + }, + "borderWidth" : 0 } }, - "legend" : { - "enabled" : "false" + "chart" : { + "type" : "column" + }, + "title" : { + "text" : "The Weekly Challenge Language" + }, + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2021-11-10 05:21:28 GMT" + }, + "series" : [ + { + "data" : [ + { + "drilldown" : "001", + "name" : "#001", + "y" : 161 + }, + { + "y" : 125, + "name" : "#002", + "drilldown" : "002" + }, + { + "drilldown" : "003", + "name" : "#003", + "y" : 81 + }, + { + "name" : "#004", + "y" : 99, + "drilldown" : "004" + }, + { + "y" : 78, + "name" : "#005", + "drilldown" : "005" + }, + { + "drilldown" : "006", + "y" : 58, + "name" : "#006" + }, + { + "drilldown" : "007", + "name" : "#007", + "y" : 64 + }, + { + "drilldown" : "008", + "name" : "#008", + "y" : 78 + }, + { + "drilldown" : "009", + "y" : 76, + "name" : "#009" + }, + { + "name" : "#010", + "y" : 65, + "drilldown" : "010" + }, + { + "name" : "#011", + "y" : 85, + "drilldown" : "011" + }, + { + "drilldown" : "012", + "y" : 89, + "name" : "#012" + }, + { + "y" : 85, + "name" : "#013", + "drilldown" : "013" + }, + { + "name" : "#014", + "y" : 101, + "drilldown" : "014" + }, + { + "drilldown" : "015", + "name" : "#015", + "y" : 99 + }, + { + "y" : 71, + "name" : "#016", + "drilldown" : "016" + }, + { + "drilldown" : "017", + "name" : "#017", + "y" : 84 + }, + { + "drilldown" : "018", + "name" : "#018", + "y" : 81 + }, + { + "y" : 103, + "name" : "#019", + "drilldown" : "019" + }, + { + "drilldown" : "020", + "y" : 101, + "name" : "#020" + }, + { + "y" : 72, + "name" : "#021", + "drilldown" : "021" + }, + { + "name" : "#022", + "y" : 68, + "drilldown" : "022" + }, + { + "y" : 97, + "name" : "#023", + "drilldown" : "023" + }, + { + "name" : "#024", + "y" : 75, + "drilldown" : "024" + }, + { + "name" : "#025", + "y" : 59, + "drilldown" : "025" + }, + { + "drilldown" : "026", + "y" : 74, + "name" : "#026" + }, + { + "name" : "#027", + "y" : 60, + "drilldown" : "027" + }, + { + "drilldown" : "028", + "y" : 80, + "name" : "#028" + }, + { + "drilldown" : "029", + "y" : 79, + "name" : "#029" + }, + { + "name" : "#030", + "y" : 117, + "drilldown" : "030" + }, + { + "drilldown" : "031", + "y" : 89, + "name" : "#031" + }, + { + "name" : "#032", + "y" : 94, + "drilldown" : "032" + }, + { + "name" : "#033", + "y" : 110, + "drilldown" : "033" + }, + { + "drilldown" : "034", + "name" : "#034", + "y" : 64 + }, + { + "y" : 64, + "name" : "#035", + "drilldown" : "035" + }, + { + "name" : "#036", + "y" : 68, + "drilldown" : "036" + }, + { + "drilldown" : "037", + "y" : 67, + "name" : "#037" + }, + { + "drilldown" : "038", + "name" : "#038", + "y" : 68 + }, + { + "drilldown" : "039", + "y" : 62, + "name" : "#039" + }, + { + "drilldown" : "040", + "name" : "#040", + "y" : 73 + }, + { + "drilldown" : "041", + "y" : 76, + "name" : "#041" + }, + { + "y" : 92, + "name" : "#042", + "drilldown" : "042" + }, + { + "y" : 68, + "name" : "#043", + "drilldown" : "043" + }, + { + "drilldown" : "044", + "name" : "#044", + "y" : 85 + }, + { + "drilldown" : "045", + "name" : "#045", + "y" : 96 + }, + { + "drilldown" : "046", + "y" : 87, + "name" : "#046" + }, + { + "drilldown" : "047", + "name" : "#047", + "y" : 84 + }, + { + "name" : "#048", + "y" : 108, + "drilldown" : "048" + }, + { + "name" : "#049", + "y" : 89, + "drilldown" : "049" + }, + { + "y" : 98, + "name" : "#050", + "drilldown" : "050" + }, + { + "drilldown" : "051", + "y" : 89, + "name" : "#051" + }, + { + "y" : 91, + "name" : "#052", + "drilldown" : "052" + }, + { + "drilldown" : "053", + "y" : 101, + "name" : "#053" + }, + { + "drilldown" : "054", + "y" : 103, + "name" : "#054" + }, + { + "name" : "#055", + "y" : 88, + "drilldown" : "055" + }, + { + "drilldown" : "056", + "name" : "#056", + "y" : 95 + }, + { + "y" : 80, + "name" : "#057", + "drilldown" : "057" + }, + { + "drilldown" : "058", + "name" : "#058", + "y" : 69 + }, + { + "drilldown" : "059", + "name" : "#059", + "y" : 89 + }, + { + "name" : "#060", + "y" : 85, + "drilldown" : "060" + }, + { + "name" : "#061", + "y" : 81, + "drilldown" : "061" + }, + { + "name" : "#062", + "y" : 58, + "drilldown" : "062" + }, + { + "name" : "#063", + "y" : 89, + "drilldown" : "063" + }, + { + "name" : "#064", + "y" : 80, + "drilldown" : "064" + }, + { + "drilldown" : "065", + "name" : "#065", + "y" : 73 + }, + { + "name" : "#066", + "y" : 84, + "drilldown" : "066" |
