From 2a270a0cc8050e78a0e947bed021699e1fe435cd Mon Sep 17 00:00:00 2001 From: pme Date: Mon, 4 Mar 2024 18:48:14 +0100 Subject: challenge-259 --- challenge-259/peter-meszaros/perl/ch-1.pl | 61 +++++++++++++++++++ challenge-259/peter-meszaros/perl/ch-2.pl | 99 +++++++++++++++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100755 challenge-259/peter-meszaros/perl/ch-1.pl create mode 100755 challenge-259/peter-meszaros/perl/ch-2.pl diff --git a/challenge-259/peter-meszaros/perl/ch-1.pl b/challenge-259/peter-meszaros/perl/ch-1.pl new file mode 100755 index 0000000000..3e16d87eb9 --- /dev/null +++ b/challenge-259/peter-meszaros/perl/ch-1.pl @@ -0,0 +1,61 @@ +#!/usr/bin/env perl +# +# You are given a start date and offset counter. Optionally you also get bank +# holiday date list. +# +# Given a number (of days) and a start date, return the number (of days) +# adjusted to take into account non-banking days. In other words: convert a +# banking day offset to a calendar day offset. +# +# Non-banking days are: +# +# a) Weekends +# b) Bank holidays +# +# Example 1 +# +# Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +# Output: '2018-07-04' +# +# Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) +# +# Example 2 +# +# Input: $start_date = '2018-06-28', $offset = 3 +# Output: '2018-07-03' +# + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; +use Date::Calc qw/Add_Delta_Days Day_of_Week/; + +my $cases = [ + [ '2018-06-28', 3, ['2018-07-03']], + [ '2018-06-28', 3], +]; + +sub banking_day_offset +{ + my $date = $_[0]->[0]; + my $offset = $_[0]->[1]; + my $holidays = $_[0]->[2]; + + my %holidays = map { $_, 1 } @$holidays; + + my @date = split(/-/, $date); + + while ($offset > 0) { + @date = Add_Delta_Days(@date, 1); + my $dow = Day_of_Week(@date); + --$offset unless $dow == 6 or $dow == 7 or defined $holidays{sprintf("%04d-%02d-%02d", @date)}; + } + return sprintf("%04d-%02d-%02d", @date); +} + +is(banking_day_offset($cases->[0]), '2018-07-04', 'Example 1'); +is(banking_day_offset($cases->[1]), '2018-07-03', 'Example 2'); +done_testing(); + +exit 0; diff --git a/challenge-259/peter-meszaros/perl/ch-2.pl b/challenge-259/peter-meszaros/perl/ch-2.pl new file mode 100755 index 0000000000..190476a03a --- /dev/null +++ b/challenge-259/peter-meszaros/perl/ch-2.pl @@ -0,0 +1,99 @@ +#!/usr/bin/env perl +# +# You are given a line like below: +# +# {% id field1="value1" field2="value2" field3=42 %} +# +# Where +# +# a) "id" can be \w+. +# b) There can be 0 or more field-value pairs. +# c) The name of the fields are \w+. +# b) The values are either number in which case we don't need double quotes or +# string in which case we need double quotes around them. +# +# The line parser should return structure like below: +# { +# name => id, +# fields => { +# field1 => value1, +# field2 => value2, +# field3 => value3, +# } +# } +# +# It should be able to parse the following edge cases too: +# {% youtube title="Title \"quoted\" done" %} +# and +# {% youtube title="Title with escaped backslash \\" %} +# +# BONUS: Extend it to be able to handle multiline tags: +# +# {% id filed1="value1" ... %} +# LINES +# {% endid %} +# +# You should expect the following structure from your line parser: +# { +# name => id, +# fields => { +# field1 => value1, +# field2 => value2, +# field3 => value3, +# } +# text => LINES +# } +# + +use strict; +use warnings; +use Test2::V0 -no_srand => 1; +use Data::Dumper; + +my $cases = [ + q/{% id field1="value1" field2="value2" field3=42 %}/, + q/{% id field1="value1" field2="va \"xxx\" lue2" field3=42 %}/, + q/{% %}/, +]; + +sub line_parser +{ + my $row = shift; + + my $href = {}; + + $row =~ /\{%\s*(\w+)/; + return undef unless $1; + + $href->{name} = $1; + + $row =~ s/\\"/\034/g; + while ($row =~ /([\w\d]+)="?(\d+|[\w\034\s]+)"?/cg) { + my $f = $1; + my $v = $2; + $v =~ s/\034/"/g; + $href->{fields}->{$f} = $v; + } + + return $href; +} + +is(line_parser($cases->[0]), { name => 'id', + fields => { + field1 => 'value1', + field2 => 'value2', + field3 => 42, + } + }, 'Example 1'); +is(line_parser($cases->[1]), { name => 'id', + fields => { + field1 => 'value1', + field2 => 'va "xxx" lue2', + field3 => 42, + } + }, 'Example 2'); +is(line_parser($cases->[2]), undef, 'Example 3'); +done_testing(); + +exit 0; + -- cgit From f4b14368b06ed73737a3b715ed0a4cd1db33ec03 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 5 Mar 2024 02:45:41 +0000 Subject: Challenge 259 Solutions (Raku) --- challenge-259/mark-anderson/raku/ch-1.raku | 55 +++++++++++++++++++++++++++++- challenge-259/mark-anderson/raku/ch-2.raku | 29 ++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 challenge-259/mark-anderson/raku/ch-2.raku diff --git a/challenge-259/mark-anderson/raku/ch-1.raku b/challenge-259/mark-anderson/raku/ch-1.raku index 26c0180e8e..f49f9b330b 100644 --- a/challenge-259/mark-anderson/raku/ch-1.raku +++ b/challenge-259/mark-anderson/raku/ch-1.raku @@ -4,10 +4,63 @@ use Test; is banking-day-offset('2018-06-28', 3), '2018-07-03'; is banking-day-offset('2018-06-28', 3, ['2018-07-03']), '2018-07-04'; is banking-day-offset('2018-06-30', 0), '2018-07-02'; -is banking-day-offset('2018-06-30', 8, ['2018-07-04', '2018-07-03']), '2018-07-16'; is banking-day-offset('2018-07-02', 0), '2018-07-02'; +is banking-day-offset('2018-06-30', 8, ['2018-07-04', '2018-07-03']), '2018-07-16'; is banking-day-offset('2018-07-16', 4), '2018-07-20'; +# E Choroba test suite +is banking-day-offset('2018-06-28', 2, ['2018-07-02', '2018-07-03']), '2018-07-04', + 'Land in the middle of holidays'; +is banking-day-offset('2018-06-28', 2, ['2018-07-01', '2018-06-30']), '2018-07-02', + 'Holidays on a weekend'; +is banking-day-offset('2024-01-01', 262), '2025-01-01', + 'Whole year'; +is banking-day-offset('2018-06-28', 101, [qw[ 2018-11-16 2018-11-19]]), '2018-11-20', + 'Holidays wrap a weekend'; +is banking-day-offset('2012-05-22', 161, ['2012-05-22']), '2013-01-03', + 'Start on a holiday'; + +my @h = < 2001-10-08 2005-02-20 2000-01-07 2003-09-26 2000-08-14 + 2008-09-22 2003-05-10 2004-05-12 2004-10-12 2008-06-12 + 2003-06-15 2003-09-20 2006-08-01 2009-02-18 2006-07-11 + 2008-04-01 2003-10-03 2008-08-07 2008-11-17 2009-02-03 + 2004-08-18 2005-04-23 2003-08-15 2007-03-22 2004-11-07 + 2004-08-13 2008-09-04 2003-06-27 2006-07-12 2003-11-06 + 2000-01-30 2006-11-26 2004-07-05 2007-03-07 2000-12-11 + 2001-01-17 2007-01-18 2002-05-01 2000-01-06 2000-03-03 + 2005-09-05 2001-01-03 2005-06-02 2003-08-15 2002-09-13 + 2006-07-15 2005-06-22 2001-10-27 2005-07-14 2004-09-19 + 2008-02-10 2003-05-10 2007-08-11 2000-02-05 2002-01-25 + 2002-03-28 2003-07-26 2007-08-13 2002-03-21 2003-03-09 + 2006-03-11 2004-03-05 2004-05-08 2006-09-24 2000-10-03 + 2001-12-19 2003-02-26 2005-10-06 2001-08-23 2004-09-25 + 2009-12-20 2004-10-10 2005-08-15 2001-11-25 2002-03-11 + 2007-10-22 2000-10-30 2009-04-14 2009-10-30 2004-09-01 + 2004-04-11 2000-04-04 2003-11-14 2004-11-16 2001-06-28 + 2008-11-18 2009-11-16 2006-01-27 2007-08-06 2009-09-14 + 2000-10-25 2001-09-14 2000-09-17 2007-01-07 2005-02-05 + 2000-09-20 2002-02-01 2003-05-08 2002-06-03 2006-12-02 + 2009-08-15 2008-11-22 2002-12-23 2002-06-08 2003-09-27 + 2004-10-08 2007-12-16 2005-12-19 2003-05-15 2007-10-30 + 2006-11-13 2005-12-04 2006-09-06 2005-05-08 2007-10-23 + 2006-05-31 2005-01-16 2009-02-15 2000-05-08 2002-04-13 + 2000-07-11 2005-05-25 2004-07-03 2007-12-03 2008-07-19 + 2009-08-27 2004-08-27 2002-03-14 2007-03-29 2005-02-03 + 2004-10-30 2000-07-14 2004-01-27 2004-12-18 2004-12-08 + 2005-11-23 2008-04-18 2000-03-06 2009-05-31 2002-08-13 + 2000-12-25 2008-09-17 2004-06-10 2003-04-29 2003-04-28 + 2000-04-30 2005-04-18 2003-08-01 2000-05-22 2009-03-18 + 2002-08-08 2008-11-15 2006-03-17 2003-07-17 2006-10-02 + 2007-01-17 2009-09-04 2000-04-22 2007-04-23 2006-01-08 + 2003-08-01 2003-08-11 2003-02-10 2007-04-08 2003-02-26 + 2002-05-16 2002-11-04 2004-01-07 2001-09-28 2001-11-29 + 2002-03-19 2009-10-08 2002-08-25 2004-08-22 2003-06-23 + 2001-05-23 2000-12-02 2000-04-26 2000-05-25 2006-05-15 + 2006-08-18 2009-12-26 2008-07-31 2009-10-02 2002-07-19 + 2006-08-01 2000-06-09 2006-04-10 >; + +is banking-day-offset('2003-04-20', 731, @h), '2006-04-05'; + sub banking-day-offset($date is copy, $offset is copy, @holidays=[]) { $date .= Date; diff --git a/challenge-259/mark-anderson/raku/ch-2.raku b/challenge-259/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..f5f3dbe472 --- /dev/null +++ b/challenge-259/mark-anderson/raku/ch-2.raku @@ -0,0 +1,29 @@ +#!/usr/bin/env raku + +say parse-line('{% id field1="value1" field2="value2" field3=42 %}'); +say parse-line('{% youtube title="Title \"quoted\" done" %}'); +say parse-line('{% youtube title="Title with escaped backslash \\" %}'); + +grammar Ch2 +{ + rule TOP { '{%' * '%}' } + token ID { \w+ } + token Key { \w+ } + token Quoted { '\"' <[\w\s]>+ '\"' } + token Unquoted { <[\w\s]>+ } + token Val { '"' [|||| '\\' ]+ '"' || \d+ } + rule KeyVal { '=' } +} + +sub parse-line($s) +{ + my %h; + my %fields; + my $m = Ch2.parse($s); + + %h = ~$m; + %fields{~.} = ~. for $m; + %h = %fields; + + return %h +} -- cgit From 3d41fe40bd74fa7980f814f698b782204c1e3a3d Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:23:48 +0000 Subject: Challenge 259 Solutions (Raku) --- challenge-259/mark-anderson/raku/ch-2.raku | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/challenge-259/mark-anderson/raku/ch-2.raku b/challenge-259/mark-anderson/raku/ch-2.raku index f5f3dbe472..09272b6c72 100644 --- a/challenge-259/mark-anderson/raku/ch-2.raku +++ b/challenge-259/mark-anderson/raku/ch-2.raku @@ -6,13 +6,13 @@ say parse-line('{% youtube title="Title with escaped backslash \\" %}'); grammar Ch2 { - rule TOP { '{%' * '%}' } - token ID { \w+ } - token Key { \w+ } - token Quoted { '\"' <[\w\s]>+ '\"' } - token Unquoted { <[\w\s]>+ } - token Val { '"' [|||| '\\' ]+ '"' || \d+ } - rule KeyVal { '=' } + rule TOP { '{%' * '%}' } + token ID { \w+ } + token Key { \w+ } + token Quoted { '\"' <[\w\s]>+ '\"' } + token Unquoted { <[\w\s]>+ } + token Val { '"' [ || || '\\' ]+ '"' || \d+ } + rule KeyVal { '=' } } sub parse-line($s) -- cgit From e921f528bf55574f74fcf6e4ded3419bdb5ddd22 Mon Sep 17 00:00:00 2001 From: Roger Bell_West Date: Tue, 5 Mar 2024 09:33:39 +0000 Subject: RogerBW solutions for challenge no. 259 --- challenge-259/roger-bell-west/javascript/ch-1.js | 30 ++++ challenge-259/roger-bell-west/kotlin/ch-1.kt | 32 ++++ challenge-259/roger-bell-west/perl/ch-1.pl | 30 ++++ challenge-259/roger-bell-west/postscript/ch-1.ps | 200 +++++++++++++++++++++++ challenge-259/roger-bell-west/python/ch-1.py | 25 +++ challenge-259/roger-bell-west/raku/ch-1.p6 | 25 +++ challenge-259/roger-bell-west/ruby/ch-1.rb | 34 ++++ challenge-259/roger-bell-west/rust/ch-1.rs | 41 +++++ challenge-259/roger-bell-west/rust/ch-2.rs | 123 ++++++++++++++ challenge-259/roger-bell-west/scala/ch-1.scala | 32 ++++ challenge-259/roger-bell-west/tests.yaml | 15 ++ 11 files changed, 587 insertions(+) create mode 100755 challenge-259/roger-bell-west/javascript/ch-1.js create mode 100644 challenge-259/roger-bell-west/kotlin/ch-1.kt create mode 100755 challenge-259/roger-bell-west/perl/ch-1.pl create mode 100644 challenge-259/roger-bell-west/postscript/ch-1.ps create mode 100755 challenge-259/roger-bell-west/python/ch-1.py create mode 100755 challenge-259/roger-bell-west/raku/ch-1.p6 create mode 100755 challenge-259/roger-bell-west/ruby/ch-1.rb create mode 100755 challenge-259/roger-bell-west/rust/ch-1.rs create mode 100755 challenge-259/roger-bell-west/rust/ch-2.rs create mode 100644 challenge-259/roger-bell-west/scala/ch-1.scala create mode 100644 challenge-259/roger-bell-west/tests.yaml diff --git a/challenge-259/roger-bell-west/javascript/ch-1.js b/challenge-259/roger-bell-west/javascript/ch-1.js new file mode 100755 index 0000000000..903fd4e349 --- /dev/null +++ b/challenge-259/roger-bell-west/javascript/ch-1.js @@ -0,0 +1,30 @@ +#! /usr/bin/node + +"use strict" + +function bankingdayoffset(start, offset, bankholidays) { + let bh = new Set(bankholidays.map(x => new Date(Date.parse(x)).toString())); + let d = new Date(Date.parse(start)); + for (let i = 1; i <= offset; i++) { + d.setDate(d.getDate() + 1); + while (bh.has(d.toString()) || d.getDay() == 0 || d.getDay() == 6) { + d.setDate(d.getDate() + 1); + } + } + return d.getFullYear().toString().padStart(4, "0") + "-" + + (d.getMonth()+1).toString().padStart(2, "0") + "-" + + d.getDate().toString().padStart(2, "0"); +} + +if (bankingdayoffset('2018-06-28', 3, ['2018-07-03']) == '2018-07-04') { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write(" "); +if (bankingdayoffset('2018-06-28', 3, []) == '2018-07-03') { + process.stdout.write("Pass"); +} else { + process.stdout.write("FAIL"); +} +process.stdout.write("\n"); diff --git a/challenge-259/roger-bell-west/kotlin/ch-1.kt b/challenge-259/roger-bell-west/kotlin/ch-1.kt new file mode 100644 index 0000000000..9b7cfb52aa --- /dev/null +++ b/challenge-259/roger-bell-west/kotlin/ch-1.kt @@ -0,0 +1,32 @@ +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +fun bankingdayoffset(start: String, offset: Int, bankholidays: List): String { + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val bh = bankholidays.map {LocalDate.parse(it, formatter)}.toSet() + var current = LocalDate.parse(start, formatter) + for (i in 1 .. offset) { + current = current.plusDays(1) + while (bh.contains(current) || current.getDayOfWeek().getValue() > 5) { + current = current.plusDays(1) + } + } + return current.format(formatter) +} + +fun main() { + + if (bankingdayoffset("2018-06-28", 3, listOf("2018-07-03")) == "2018-07-04") { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (bankingdayoffset("2018-06-28", 3, emptyList()) == "2018-07-03") { + print("Pass") + } else { + print("Fail") + } + println("") + +} diff --git a/challenge-259/roger-bell-west/perl/ch-1.pl b/challenge-259/roger-bell-west/perl/ch-1.pl new file mode 100755 index 0000000000..ccaf86c903 --- /dev/null +++ b/challenge-259/roger-bell-west/perl/ch-1.pl @@ -0,0 +1,30 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use experimental 'signatures'; + +use Test::More tests => 2; + +is(bankingdayoffset('2018-06-28', 3, ['2018-07-03']), '2018-07-04', 'example 1'); +is(bankingdayoffset('2018-06-28', 3, []), '2018-07-03', 'example 2'); + +use DateTime; +use DateTime::Format::Strptime; + +sub bankingdayoffset($start, $offset, $bankholidays) { + my $strp = DateTime::Format::Strptime->new( + pattern => '%Y-%m-%d', + strict => 1, + time_zone => 'GMT', + ); + my %bh = map {$strp->parse_datetime($_) => 1} @{$bankholidays}; + my $current = $strp->parse_datetime($start); + foreach (1 .. $offset) { + $current = $current->add(days => 1); + while (exists $bh{$current} || $current->day_of_week > 5) { + $current = $current->add(days => 1); + } + } + return $current->strftime('%Y-%m-%d'); +} diff --git a/challenge-259/roger-bell-west/postscript/ch-1.ps b/challenge-259/roger-bell-west/postscript/ch-1.ps new file mode 100644 index 0000000000..6e2e31189f --- /dev/null +++ b/challenge-259/roger-bell-west/postscript/ch-1.ps @@ -0,0 +1,200 @@ +%!PS + +% begin included library code +% see https://codeberg.org/Firedrake/postscript-libraries/ +/test { + /test.count test.count 1 add def + { + /test.pass test.pass 1 add def + } { + ( ) print + test.count (....) cvs print + (-fail) print + } ifelse +} bind def + +/jd2ymd { + 15 dict begin + /y 4716 def + /v 3 def + /j 1401 def + /u 5 def + /m 2 def + /s 153 def + /n 12 def + /w 2 def + /r 4 def + /B 274277 def + /p 1461 def + /C -38 def + dup + 4 mul B add 146097 idiv 3 mul 4 idiv C add j add add /f exch def + r f mul v add /e exch def + e p mod r idiv u mul w add /h exch def + /day h s mod u idiv 1 add def + /month h s idiv m add n mod 1 add def + /year e p idiv y sub n m add month sub n idiv add def + [ year month day ] + end +} bind def + +/map { % array proc -> array + 2 dict begin + /p exch def + [ exch + { + p + } forall + ] + end +} bind def + +/toset { % array -> dict of (value, true) + << exch + { + true + } forall + >> +} bind def + +/test.end { + ( ) print + test.count 0 gt { + (Passed ) print + test.pass (...) cvs print + (/) print + test.count (...) cvs print + ( \() print + test.pass 100 mul test.count idiv (...) cvs print + (%\)) print + (\r\n) print + } if +} bind def + +/strjoin % [(a) (b) (c)] (j) -> (ajbjc) +{ + 3 dict begin + /j exch def + dup 0 get /out exch def + /first true def + { + first { + pop + /first false def + } { + out j strconcat + exch strconcat + /out exch def + } ifelse + } forall + out + end +} bind def + +/a2s { + 2 dict begin + /i exch def + i length dup string /o exch def + 1 sub 0 exch 1 exch { + dup i 3 -1 roll get o 3 1 roll put + } for + o + end +} bind def + + +/test.start { + print (:) print + /test.pass 0 def + /test.count 0 def +} bind def + +/s2a { + [ exch { } forall ] +} bind def + +/ymd2jd { + 4 dict begin + aload pop + /d exch def + /m exch def + /y exch def + /mn m 14 sub 12 idiv def + y 4800 add mn add 1461 mul 4 idiv + mn 12 mul neg 2 sub m add 367 mul 12 idiv add + y 4900 add mn add 100 idiv 3 mul 4 idiv sub + d add + 32075 sub + end +} bind def + +/jd2dow { + 1 add 7 mod +} bind def + +/strconcat % (a) (b) -> (ab) +{ + [ + 3 -1 roll + s2a aload length + 2 add -1 roll + s2a aload pop + ] a2s +} bind def + + +% end included library code + +/s2jd { + 0 dict begin + /s exch def + [ exch + s 0 4 getinterval cvi + s 5 2 getinterval cvi + s 8 2 getinterval cvi + ] ymd2jd + end +} bind def + +/flz { + 0 dict begin + /width exch def + /value exch def + value type /stringtype ne { + /value value width string cvs def + } if + /out [ width { 48 } repeat ] a2s def + out width value length sub value putinterval + out + end +} bind def + +/bankingdayoffset { + 0 dict begin + /bh exch { s2jd } map toset def + /offset exch def + /d exch s2jd def + offset { + /d d 1 add def + { + d jd2dow dup + 0 gt exch 6 lt and + bh d known not and { + exit + } if + /d d 1 add def + } loop + } repeat + [ + d jd2ymd aload pop + 2 flz 3 1 roll + 2 flz 3 1 roll + 4 flz 3 1 roll + ] (-) strjoin + end +} bind def + +(bankingdayoffset) test.start +(2018-06-28) 3 [(2018-07-03)] bankingdayoffset (2018-07-04) eq test +(2018-06-28) 3 [] bankingdayoffset (2018-07-03) eq test +test.end diff --git a/challenge-259/roger-bell-west/python/ch-1.py b/challenge-259/roger-bell-west/python/ch-1.py new file mode 100755 index 0000000000..fef13ed084 --- /dev/null +++ b/challenge-259/roger-bell-west/python/ch-1.py @@ -0,0 +1,25 @@ +#! /usr/bin/python3 + +from datetime import date, timedelta + +def bankingdayoffset(start, offset, bankholidays): + bh = set(date.fromisoformat(i) for i in bankholidays) + d = date.fromisoformat(start) + day = timedelta(days = 1) + for _ in range(offset): + d += day + while d in bh or d.weekday() > 4: + d += day + return d.strftime("%Y-%m-%d") + +import unittest + +class TestBankingdayoffset(unittest.TestCase): + + def test_ex1(self): + self.assertEqual(bankingdayoffset("2018-06-28", 3, ["2018-07-03"]), "2018-07-04", 'example 1') + + def test_ex2(self): + self.assertEqual(bankingdayoffset("2018-06-28", 3, []), "2018-07-03", 'example 2') + +unittest.main() diff --git a/challenge-259/roger-bell-west/raku/ch-1.p6 b/challenge-259/roger-bell-west/raku/ch-1.p6 new file mode 100755 index 0000000000..f95a7cd92c --- /dev/null +++ b/challenge-259/roger-bell-west/raku/ch-1.p6 @@ -0,0 +1,25 @@ +#! /usr/bin/raku + +use Test; + +plan 2; + +is(bankingdayoffset('2018-06-28', 3, ['2018-07-03']), '2018-07-04', 'example 1'); +is(bankingdayoffset('2018-06-28', 3, []), '2018-07-03', 'example 2'); + +sub parsedate($s) { + $s ~~ /(<[0..9]>+)\D(<[0..9]>+)\D(<[0..9]>+)/; + return Date.new($0, $1, $2); +} + +sub bankingdayoffset($start, $offset, @bankholidays) { + my $bh = Set(@bankholidays.map({parsedate($_)})); + my $current = parsedate($start); + for (1 .. $offset) { + $current = $current.later(days => 1); + while ($bh{$current}:exists || $current.day-of-week > 5) { + $current = $current.later(days => 1); + } + } + return $current.yyyy-mm-dd; +} diff --git a/challenge-259/roger-bell-west/ruby/ch-1.rb b/challenge-259/roger-bell-west/ruby/ch-1.rb new file mode 100755 index 0000000000..4ea9277f76 --- /dev/null +++ b/challenge-259/roger-bell-west/ruby/ch-1.rb @@ -0,0 +1,34 @@ +#! /usr/bin/ruby + +require 'set' +require 'time' + +def parsedate(s) + return Time.strptime(s + " 12:00 +0000", '%Y-%m-%d %H:%M %z') +end + +def bankingdayoffset(start, offset, bankholidays) + bh = Set.new(bankholidays.map {|d| parsedate(d)}) + s = parsedate(start) + 1.upto(offset) do + s += 86400 + while bh.include?(s) || s.wday == 0 || s.wday == 6 do + s += 86400 + end + end + return s.strftime('%Y-%m-%d') +end + +require 'test/unit' + +class TestBankingdayoffset < Test::Unit::TestCase + + def test_ex1 + assert_equal('2018-07-04', bankingdayoffset('2018-06-28', 3, ['2018-07-03'])) + end + + def test_ex2 + assert_equal('2018-07-03', bankingdayoffset('2018-06-28', 3, [])) + end + +end diff --git a/challenge-259/roger-bell-west/rust/ch-1.rs b/challenge-259/roger-bell-west/rust/ch-1.rs new file mode 100755 index 0000000000..38598b9589 --- /dev/null +++ b/challenge-259/roger-bell-west/rust/ch-1.rs @@ -0,0 +1,41 @@ +// [dependencies] +// chrono = "0.4.34" + +use chrono::{Datelike, NaiveDate}; +use std::collections::HashSet; + +#[test] +fn test_ex1() { + assert_eq!( + bankingdayoffset("2018-06-28", 3, vec!["2018-07-03"]), + "2018-07-04" + ); +} + +#[test] +fn test_ex2() { + assert_eq!( + bankingdayoffset("2018-06-28", 3, Vec::<&str>::new()), + "2018-07-03" + ); +} + +fn parsedate(s: &str) -> NaiveDate { + NaiveDate::parse_from_str(s, "%Y-%m-%d").unwrap() +} + +fn bankingdayoffset( + start: &str, + offset: u32, + bankholidays: Vec<&str>, +) -> String { + let bh = bankholidays.iter().map(|i| parsedate(i)).collect::>(); + let mut d = parsedate(start); + for _ in 0..offset { + d = d.succ_opt().unwrap(); + while bh.contains(&d) || d.weekday().num_days_from_monday() > 4 { + d = d.succ_opt().unwrap(); + } + } + d.format("%Y-%m-%d").to_string() +} diff --git a/challenge-259/roger-bell-west/rust/ch-2.rs b/challenge-259/roger-bell-west/rust/ch-2.rs new file mode 100755 index 0000000000..70a0124249 --- /dev/null +++ b/challenge-259/roger-bell-west/rust/ch-2.rs @@ -0,0 +1,123 @@ +#! /bin/sh +//usr/bin/env rustc --test $0 -o ${0}x && ./${0}x --nocapture; rm -f ${0}x ; exit + +use std::collections::{HashMap, VecDeque}; + +#[derive(PartialEq, Debug)] +pub struct Lump { + id: String, + fields: HashMap, +} + +#[test] +fn test_ex1() { + assert_eq!( + lineparser( + "{% id field1=\"value1\" field2=\"value2\" field3=42 %}" + ), + Lump { + id: "id".to_string(), + fields: HashMap::from([ + ("field3".to_string(), "42".to_string()), + ("field2".to_string(), "value2".to_string()), + ("field1".to_string(), "value1".to_string()) + ]) + } + ); +} + +#[test] +fn test_ex2() { + assert_eq!( + lineparser("{% youtube title=\"Title \\\"quoted\\\" done\" %}"), + Lump { + id: "youtube".to_string(), + fields: HashMap::from([( + "title".to_string(), + "Title \"quoted\" done".to_string() + )]) + } + ); +} + +#[test] +fn test_ex3() { + assert_eq!( + lineparser( + "{% youtube title=\"Title with escaped backslash \\\\\" %}" + ), + Lump { + id: "youtube".to_string(), + fields: HashMap::from([( + "title".to_string(), + "Title with escaped backslash \\".to_string() + )]) + } + ); +} + +#[derive(PartialEq, Debug)] +enum State { + Outside, + PreID, + InID, + InterField, + FieldName, + FieldValue, + FieldValueQuoted, +} + +fn lineparser(line: &str) -> Lump { + let mut l = line.chars().collect::>(); + let mut state = State::Outside; + let mut trail: Vec = Vec::new(); + let mut fieldname = "".to_string(); + let mut out = Lump { id: "".to_string(), fields: HashMap::new() }; + while l.len() > 0 { + let mut c = l.pop_front().unwrap(); + if state == State::Outside && c == '{' { + c = l.pop_front().unwrap(); + if c == '%' { + state = State::PreID; + } + } else if (state == State::PreID || state == State::InID) && c != ' ' { + trail.push(c); + state = State::InID; + } else if state == State::InID && c == ' ' { + out.id = trail.into_iter().collect(); + trail = Vec::new(); + state = State::InterField; + } else if (state == State::InterField || state == State::FieldName) + && c != ' ' + && c != '=' + && c != '%' + { + trail.push(c); + state = State::FieldName; + } else if state == State::FieldName && c == '=' { + fieldname = trail.into_iter().collect(); + trail = Vec::new(); + state = State::FieldValue; + } else if state == State::FieldValue && trail.len() == 0 && c == '"' { + state = State::FieldValueQuoted; + } else if state == State::FieldValue || state == State::FieldValueQuoted + { + let mut literal = false; + if c == '\\' { + c = l.pop_front().unwrap(); + literal = true; + } + if (c == ' ' && state == State::FieldValue) + || (c == '"' && state == State::FieldValueQuoted && !literal) + { + out.fields + .insert(fieldname.clone(), trail.into_iter().collect()); + trail = Vec::new(); + state = State::InterField; + } else { + trail.push(c); + } + } + } + out +} diff --git a/challenge-259/roger-bell-west/scala/ch-1.scala b/challenge-259/roger-bell-west/scala/ch-1.scala new file mode 100644 index 0000000000..6e5b2e3f52 --- /dev/null +++ b/challenge-259/roger-bell-west/scala/ch-1.scala @@ -0,0 +1,32 @@ +import java.time.LocalDate +import java.time.format.DateTimeFormatter + +object Bankingdayoffset { + def bankingdayoffset(start: String, offset: Int, bankholidays: List[String]): String = { + val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd") + val bh = bankholidays.map(d => LocalDate.parse(d, formatter)).toSet + var current = LocalDate.parse(start, formatter) + for (i <- 1 to offset) { + current = current.plusDays(1) + while (bh.contains(current) || current.getDayOfWeek().getValue() > 5) { + current = current.plusDays(1) + } + } + return current.format(formatter) + } + def main(args: Array[String]) { + if (bankingdayoffset("2018-06-28", 3, List("2018-07-03")) == "2018-07-04") { + print("Pass") + } else { + print("Fail") + } + print(" ") + if (bankingdayoffset("2018-06-28", 3, List()) == "2018-07-03") { + print("Pass") + } else { + print("Fail") + } + println("") + + } +} diff --git a/challenge-259/roger-bell-west/tests.yaml b/challenge-259/roger-bell-west/tests.yaml new file mode 100644 index 0000000000..3bc7c11499 --- /dev/null +++ b/challenge-259/roger-bell-west/tests.yaml @@ -0,0 +1,15 @@ +--- +ch-1: + - function: bankingdayoffset + multiarg: true + arguments: + - 2018-06-28 + - 3 + - - 2018-07-03 + result: 2018-07-04 + - multiarg: true + arguments: + - 2018-06-28 + - 3 + - [] + result: 2018-07-03 -- cgit From a188681389c509987a2d113a8deaa06ce082b3e3 Mon Sep 17 00:00:00 2001 From: Mariano Spadaccini Date: Tue, 5 Mar 2024 12:17:12 +0100 Subject: Add ch-1 in Perl, Go, Elixir, Python, Ruby --- challenge-259/spadacciniweb/elixir/ch-1.exs | 57 ++++++++++++++++++++ challenge-259/spadacciniweb/go/ch-1.go | 80 +++++++++++++++++++++++++++++ challenge-259/spadacciniweb/perl/ch-1.pl | 76 +++++++++++++++++++++++++++ challenge-259/spadacciniweb/python/ch-1.py | 54 +++++++++++++++++++ challenge-259/spadacciniweb/ruby/ch-1.rb | 56 ++++++++++++++++++++ 5 files changed, 323 insertions(+) create mode 100644 challenge-259/spadacciniweb/elixir/ch-1.exs create mode 100644 challenge-259/spadacciniweb/go/ch-1.go create mode 100644 challenge-259/spadacciniweb/perl/ch-1.pl create mode 100644 challenge-259/spadacciniweb/python/ch-1.py create mode 100644 challenge-259/spadacciniweb/ruby/ch-1.rb diff --git a/challenge-259/spadacciniweb/elixir/ch-1.exs b/challenge-259/spadacciniweb/elixir/ch-1.exs new file mode 100644 index 0000000000..434545bfd9 --- /dev/null +++ b/challenge-259/spadacciniweb/elixir/ch-1.exs @@ -0,0 +1,57 @@ +# Task 1: Banking Day Offset +# Submitted by: Lee Johnson +# +# You are given a start date and offset counter. Optionally you also get bank holiday date list. +# +# Given a number (of days) and a start date, return the number (of days) adjusted to take into account non-banking days. In other words: convert a banking day offset to a calendar day offset. +# +# Non-banking days are: +# a) Weekends +# b) Bank holidays +# +# Example 1 +# Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +# Output: '2018-07-04' +# +# Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) +# +# Example 2 +# Input: $start_date = '2018-06-28', $offset = 3 +# Output: '2018-07-03' + +defmodule BankingDay do + + def banking_day_offset(start_date, offset, bank_holidays) do + out(start_date, offset, bank_holidays, + next_working_day( Date.from_iso8601!(start_date), offset, bank_holidays) + ) + end + + def next_working_day(dt, offset, bank_holidays) when offset > 0 do + dt1 = Date.add(dt, 1) + if Date.day_of_week(dt1) >= 6 || Enum.member?(bank_holidays, "#{dt1}") do + next_working_day(dt1, offset, bank_holidays) + else + next_working_day(dt1, offset-1, bank_holidays) + end + end + + def next_working_day(dt, 0, _bank_holidays) do + Date.to_iso8601(dt) + end + + def out(start_date, offset, bank_holidays, ymd) do + IO.write( "(start #{start_date} offset #{offset} Bank holidays [" <> Enum.join(bank_holidays, ", ") <> "]) -> ") + IO.puts( ymd ) + end +end + +start_date = "2018-06-28" +offset = 3 +bank_holidays = ["2018-07-03"] +BankingDay.banking_day_offset(start_date, offset, bank_holidays) + +start_date = "2018-06-28" +offset = 3 +bank_holidays = [] +BankingDay.banking_day_offset(start_date, offset, bank_holidays) diff --git a/challenge-259/spadacciniweb/go/ch-1.go b/challenge-259/spadacciniweb/go/ch-1.go new file mode 100644 index 0000000000..37446a936b --- /dev/null +++ b/challenge-259/spadacciniweb/go/ch-1.go @@ -0,0 +1,80 @@ +/* +Task 1: Banking Day Offset +Submitted by: Lee Johnson + +You are given a start date and offset counter. Optionally you also get bank holiday date list. + +Given a number (of days) and a start date, return the number (of days) adjusted to take into account non-banking days. In other words: convert a banking day offset to a calendar day offset. + +Non-banking days are: +a) Weekends +b) Bank holidays + +Example 1 +Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +Output: '2018-07-04' + +Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) + +Example 2 +Input: $start_date = '2018-06-28', $offset = 3 +Output: '2018-07-03' +*/ + +package main + +import ( + "fmt" + "log" + "strings" + "time" +) + +func contains(s []string, str string) bool { + for _, v := range s { + if v == str { + return true + } + } + return false +} + +func no_banking_day(t time.Time, bank_holidays []string) bool { + ymd := t.Format("2006-01-02") + if (t.Weekday() == 0 || t.Weekday() == 6 || contains(bank_holidays, ymd)) { + return true + } + return false +} + +func banking_day_offset(start_date string, offset int, bank_holidays []string) { + t, err := time.Parse("2006-01-02", start_date) + if err != nil { + log.Fatal(err) + } + + for i := 1; i <= offset; i++ { + t = t.AddDate(0, 0, 1) + for no_banking_day(t, bank_holidays) { + t = t.AddDate(0, 0, 1) + } + } + + fmt.Printf("start %s offset %d Bank holidays [%s]) -> %s\n", + start_date, offset, + strings.Join(bank_holidays, " "), + t.Format("2006-01-02")) +} + +func main() { + start_date := "2018-06-28" + offset := 3; + bank_holidays := []string{"2018-07-03"} + banking_day_offset(start_date, offset, bank_holidays) + + start_date = "2018-06-28" + offset = 3; + bank_holidays = []string{} + banking_day_offset(start_date, offset, bank_holidays) +} + diff --git a/challenge-259/spadacciniweb/perl/ch-1.pl b/challenge-259/spadacciniweb/perl/ch-1.pl new file mode 100644 index 0000000000..8f804849b6 --- /dev/null +++ b/challenge-259/spadacciniweb/perl/ch-1.pl @@ -0,0 +1,76 @@ +#!/usr/bin/env perl + +# Task 1: Banking Day Offset +# Submitted by: Lee Johnson +# +# You are given a start date and offset counter. Optionally you also get bank holiday date list. +# +# Given a number (of days) and a start date, return the number (of days) adjusted to take into account non-banking days. In other words: convert a banking day offset to a calendar day offset. +# +# Non-banking days are: +# a) Weekends +# b) Bank holidays +# +# Example 1 +# Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +# Output: '2018-07-04' +# +# Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) +# +# Example 2 +# Input: $start_date = '2018-06-28', $offset = 3 +# Output: '2018-07-03' + +use strict; +use warnings; +use DateTime; + +my $start_date = '2018-06-28'; +my $offset = 3; +my $bank_holidays = ['2018-07-03']; +banking_day_offset($start_date, $offset, $bank_holidays); + +$start_date = '2018-06-28'; +$offset = 3; +$bank_holidays = []; +banking_day_offset($start_date, $offset, $bank_holidays); + +exit 0; + +sub banking_day_offset { + my $start_date = shift; + my $offset = shift; + my $bank_holidays = shift; + + my ($yyyy, $mm, $dd) = split /-/, $start_date; + my $dt = DateTime->new( + year => $yyyy, + month => $mm, + day => $dd + ); + + foreach (1..$offset) { + $dt->add( days => 1 ); + while (no_banking_day($dt)) { + $dt->add( days => 1 ); + } + } + + printf "(start %s offset %s Bank holidays [%s]) -> %s\n", + $start_date, + $offset, + (join ' / ', @$bank_holidays ), + $dt->ymd; + + return undef; +} + +sub no_banking_day { + my $dt = shift; + my $ymd = $dt->ymd; + return 1 + if $dt->day_of_week >= 6 + || + grep /$ymd/, @$bank_holidays; + return 0; +} diff --git a/challenge-259/spadacciniweb/python/ch-1.py b/challenge-259/spadacciniweb/python/ch-1.py new file mode 100644 index 0000000000..23cedaa661 --- /dev/null +++ b/challenge-259/spadacciniweb/python/ch-1.py @@ -0,0 +1,54 @@ +# Task 1: Banking Day Offset +# Submitted by: Lee Johnson +# +# You are given a start date and offset counter. Optionally you also get bank holiday date list. +# +# Given a number (of days) and a start date, return the number (of days) adjusted to take into account non-banking days. In other words: convert a banking day offset to a calendar day offset. +# +# Non-banking days are: +# a) Weekends +# b) Bank holidays +# +# Example 1 +# Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +# Output: '2018-07-04' +# +# Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) +# +# Example 2 +# Input: $start_date = '2018-06-28', $offset = 3 +# Output: '2018-07-03' + +from dateutil.parser import * +import datetime + +def banking_day_offset(start_date, offset, bank_holidays): + dt = parse(start_date, dayfirst = False, yearfirst = True) + + for i in range(1,5): + dt += datetime.timedelta(days=1) + while no_banking_day(dt): + dt += datetime.timedelta(days=1) + + print("(start %s offset %s Bank holidays [%s]) -> %s" % + (start_date, offset, + ' / '.join(bank_holidays), + dt.strftime('%Y-%m-%d') + ) + ) + +def no_banking_day(dt): + if (dt.weekday() >= 6) or (dt.strftime('%Y-%m-%d') in bank_holidays): + return 1 + return 0 + +if __name__ == "__main__": + start_date = '2018-06-28' + offset = 3 + bank_holidays = ['2018-07-03'] + banking_day_offset(start_date, offset, bank_holidays) + + start_date = '2018-06-28'; + offset = 3; + bank_holidays = []; + banking_day_offset(start_date, offset, bank_holidays) diff --git a/challenge-259/spadacciniweb/ruby/ch-1.rb b/challenge-259/spadacciniweb/ruby/ch-1.rb new file mode 100644 index 0000000000..b069356a52 --- /dev/null +++ b/challenge-259/spadacciniweb/ruby/ch-1.rb @@ -0,0 +1,56 @@ +# Task 1: Banking Day Offset +# Submitted by: Lee Johnson +# +# You are given a start date and offset counter. Optionally you also get bank holiday date list. +# +# Given a number (of days) and a start date, return the number (of days) adjusted to take into account non-banking days. In other words: convert a banking day offset to a calendar day offset. +# +# Non-banking days are: +# a) Weekends +# b) Bank holidays +# +# Example 1 +# Input: $start_date = '2018-06-28', $offset = 3, $bank_holidays = ['2018-07-03'] +# Output: '2018-07-04' +# +# Thursday bumped to Wednesday (3 day offset, with Monday a bank holiday) +# +# Example 2 +# Input: $start_date = '2018-06-28', $offset = 3 +# Output: '2018-07-03' + +require 'date' + +def banking_day_offset(start_date, offset, bank_holidays) + dt = Date.strptime(start_date, '%Y-%m-%d') + + (1..offset).each do |i| + dt += 1 + while no_banking_day(dt, bank_holidays) == true + dt += 1 + end + end + + printf "(start %s offset %s Bank holidays [%s]) -> %s\n", + start_date, + offset, + bank_holidays.join(" / "), + dt.strftime('%Y-%m-%d'); +end + +def no_banking_day(dt, bank_holidays) + if dt.strftime("%u").to_i >= 6 or bank_holidays.include?( dt.strftime('%Y-%m-%d') ) + return true + end + false +end + +start_date = '2018-06-28' +offset = 3 +bank_holidays = ['2018-07-03'] +banking_day_offset(start_date, offset, bank_holidays) + +start_date = '2018-06-28'; +offset = 3; +bank_holidays = []; +banking_day_offset(start_date, offset, bank_holidays); -- cgit From 9afcaea2974dfbb52662e6fc3802bef0c64e65be Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 5 Mar 2024 12:32:31 +0000 Subject: - Added solutions by Peter Meszaros. - Added solutions by Dave Jacoby. - Added solutions by Mark Anderson. - Added solutions by Roger Bell_West. - Added solutions by Mariano Spadaccini. --- challenge-259/eric-cheung/python/ch-1.py | 23 + challenge-259/eric-cheung/python/ch-2.py | 57 + stats/pwc-current.json | 136 ++- stats/pwc-language-breakdown-summary.json | 32 +- stats/pwc-language-breakdown.json | 1620 ++++++++++++++--------------- stats/pwc-leaders.json | 432 ++++---- stats/pwc-summary-1-30.json | 96 +- stats/pwc-summary-121-150.json | 54 +- stats/pwc-summary-151-180.json | 58 +- stats/pwc-summary-181-210.json | 86 +- stats/pwc-summary-211-240.json | 116 +-- stats/pwc-summary-241-270.json | 116 +-- stats/pwc-summary-271-300.json | 40 +- stats/pwc-summary-301-330.json | 54 +- stats/pwc-summary-31-60.json | 118 +-- stats/pwc-summary-61-90.json | 108 +- stats/pwc-summary-91-120.json | 48 +- stats/pwc-summary.json | 62 +- 18 files changed, 1700 insertions(+), 1556 deletions(-) create mode 100755 challenge-259/eric-cheung/python/ch-1.py create mode 100755 challenge-259/eric-cheung/python/ch-2.py diff --git a/challenge-259/eric-cheung/python/ch-1.py b/challenge-259/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..794b79e029 --- /dev/null +++ b/challenge-259/eric-cheung/python/ch-1.py @@ -0,0 +1,23 @@ + +from datetime import datetime, timedelta + +strDateFormat = "%Y-%m-%d" + +## Example 1 +## strStartDate = "2018-06-28" +## nOffset = 3 +## arrBankHoliday = ["2018-07-03"] + +## Example 2 +strStartDate = "2018-06-28" +nOffset = 3 +arrBankHoliday = [] + +objOutputDate = datetime.strptime(strStartDate, strDateFormat) + +while nOffset > 0: + objOutputDate = objOutputDate + timedelta(days = 1) + if objOutputDate.weekday() < 5 and not objOutputDate.strftime(strDateFormat) in arrBankHoliday: + nOffset = nOffset - 1 + +print (objOutputDate.strftime(strDateFormat)) diff --git a/challenge-259/eric-cheung/python/ch-2.py b/challenge-259/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..271db58f8a --- /dev/null +++ b/challenge-259/eric-cheung/python/ch-2.py @@ -0,0 +1,57 @@ + +## Remarks +## https://stackoverflow.com/questions/74569246/replace-space-in-between-double-quote-to-underscore + +import json +import re + +def GetDoubleQuote (strInput): + if strInput[0] == "\"": + return strInput + return "\"" + strInput + "\"" + +def repl(strInput): + return strInput[0].replace(' ', '^') + + +## strLineInput = '{% id field1="value1" field2="value2" field3=42 %}' ## Example 1 +## strLineInput = '{% youtube title="Title \"quoted\" done" %}' ## Example 2 +## strLineInput = '{% youtube title="Title quoted done" %}' ## Example 3 +## strLineInput = '{% youtube title="Title with escaped backslash \\" %}' ## Example 4 +## strLineInput = '{% id %}' ## Example 5 +strLineInput = ''' +{% id field1="value1" field2="value2" field3=42 %} +LINES +{% endid %} +''' ## Example 6 + +bMultipleLine = False +arrMultipleLineSplit = strLineInput.split("\n") + +if len(arrMultipleLineSplit) > 1: + bMultipleLine = True + strLineInput = arrMultipleLineSplit[1] + +strReplacePattern = re.compile(r'\"[^\"]+\"') +strLineInput = re.sub(strReplacePattern, repl, strLineInput) + +arrLineSplit = strLineInput.replace("%", "").split() +arrLineSplit = [elemLoop.replace('^', ' ') for elemLoop in arrLineSplit] + +arrLineSplit[1] = GetDoubleQuote("name") + " : " + GetDoubleQuote(arrLineSplit[1]) +for nIndx in range(2, len(arrLineSplit) - 1): + arrLineSplit[nIndx] = " : ".join([GetDoubleQuote(elemLoop) if nIndx == 0 else elemLoop for nIndx, elemLoop in enumerate(arrLineSplit[nIndx].split("="))]) + +strJsonOutput = "{" + arrLineSplit[1] +if len(arrLineSplit) > 3: + strJsonOutput = strJsonOutput + ", " + GetDoubleQuote("fields") + " : " + "{" + ", ".join(arrLineSplit[2:-1]) + "}" + +if bMultipleLine: + strJsonOutput = strJsonOutput + ", " + GetDoubleQuote("text") + " : " + GetDoubleQuote(arrMultipleLineSplit[2]) + +strJsonOutput = strJsonOutput + "}" + +## print (arrLineSplit) +## print (strJsonOutput) +print (json.loads(strJsonOutput)) +## print (json.loads(strJsonOutput)["name"]) diff --git a/stats/pwc-current.json b/stats/pwc-current.json index 8498152edf..0d00311865 100644 --- a/stats/pwc-current.json +++ b/stats/pwc-current.json @@ -1,21 +1,32 @@ { + "title" : { + "text" : "The Weekly Challenge - 259" + }, + "xAxis" : { + "type" : "category" + }, "series" : [ { "data" : [ { "y" : 2, - "drilldown" : "David Ferrone", - "name" : "David Ferrone" + "drilldown" : "Dave Jacoby", + "name" : "Dave Jacoby" }, { + "name" : "David Ferrone", "y" : 2, - "drilldown" : "E. Choroba", - "name" : "E. Choroba" + "drilldown" : "David Ferrone" }, { + "name" : "E. Choroba", "y" : 2, + "drilldown" : "E. Choroba" + }, + { + "name" : "Feng Chang", "drilldown" : "Feng Chang", - "name" : "Feng Chang" + "y" : 2 }, { "name" : "Luca Ferrari", @@ -23,29 +34,44 @@ "y" : 11 }, { - "name" : "Mark Anderson", "y" : 1, + "drilldown" : "Mariano Spadaccini", + "name" : "Mariano Spadaccini" + }, + { + "name" : "Mark Anderson", + "y" : 2, "drilldown" : "Mark Anderson" + }, + { + "name" : "Peter Meszaros", + "drilldown" : "Peter Meszaros", + "y" : 2 + }, + { + "name" : "Roger Bell_West", + "drilldown" : "Roger Bell_West", + "y" : 2 } ], "name" : "The Weekly Challenge - 259", "colorByPoint" : 1 } ], - "title" : { - "text" : "The Weekly Challenge - 259" + "legend" : { + "enabled" : 0 }, "drilldown" : { "series" : [ { - "id" : "David Ferrone", + "name" : "Dave Jacoby", + "id" : "Dave Jacoby", "data" : [ [ "Perl", 2 ] - ], - "name" : "David Ferrone" + ] }, { "data" : [ @@ -54,21 +80,30 @@ 2 ] ], + "id" : "David Ferrone", + "name" : "David Ferrone" + }, + { + "id" : "E. Choroba", "name" : "E. Choroba", - "id" : "E. Choroba" + "data" : [ + [ + "Perl", + 2 + ] + ] }, { - "id" : "Feng Chang", "data" : [ [ "Raku", 2 ] ], - "name" : "Feng Chang" + "name" : "Feng Chang", + "id" : "Feng Chang" }, { - "name" : "Luca Ferrari", "data" : [ [ "Raku", @@ -79,22 +114,67 @@ 9 ] ], - "id" : "Luca Ferrari" + "id" : "Luca Ferrari", + "name" : "Luca Ferrari" }, { - "id" : "Mark Anderson", + "name" : "Mariano Spadaccini", + "id" : "Mariano Spadaccini", + "data" : [ + [ + "Perl", + 1 + ] + ] + }, + { + "data" : [ + [ + "Raku", + 2 + ] + ], "name" : "Mark Anderson", + "id" : "Mark Anderson" + }, + { + "data" : [ + [ + "Perl", + 2 + ] + ], + "id" : "Peter Meszaros", + "name" : "Peter Meszaros" + }, + { "data" : [ + [ + "Perl", + 1 + ], [ "Raku", 1 ] - ] + ], + "id" : "Roger Bell_West", + "name" : "Roger Bell_West" } ] }, - "legend" : { - "enabled" : 0 + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } + }, + "subtitle" : { + "text" : "[Champions: 9] Last updated at 2024-03-05 12:27:05 GMT" + }, + "tooltip" : { + "headerFormat" : "{series.name}
", + "followPointer" : 1, + "pointFormat" : "{point.name}: {point.y:f}
" }, "plotOptions" : { "series" : { @@ -107,21 +187,5 @@ }, "chart" : { "type" : "column" - }, - "yAxis" : { - "title" : { - "text" : "Total Solutions" - } - }, - "tooltip" : { - "followPointer" : 1, - "pointFormat" : "{point.name}: {point.y:f}
", - "headerFormat" : "{series.name}
" - }, - "subtitle" : { - "text" : "[Champions: 5] Last updated at 2024-03-04 19:05:07 GMT" - }, - "xAxis" : { - "type" : "category" } } diff --git a/stats/pwc-language-breakdown-summary.json b/stats/pwc-language-breakdown-summary.json index 8c85378f64..b53458fd58 100644 --- a/stats/pwc-language-breakdown-summary.json +++ b/stats/pwc-language-breakdown-summary.json @@ -2,8 +2,11 @@ "tooltip" : { "pointFormat" : "{point.y:.0f}" }, + "chart" : { + "type" : "column" + }, "subtitle" : { - "text" : "Last updated at 2024-03-04 19:05:07 GMT" + "text" : "Last updated at 2024-03-05 12:27:05 GMT" }, "yAxis" : { "min" : 0, @@ -14,12 +17,8 @@ "legend" : { "enabled" : "false" }, - "chart" : { - "type" : "column" - }, "series" : [ { - "name" : "Contributions", "data" : [ [ "Blog", @@ -27,37 +26,38 @@ ], [ "Perl", - 13351 + 13357 ], [ "Raku", - 7766 + 7768 ] ], + "name" : "Contributions", "dataLabels" : { - "rotation" : -90, + "color" : "#FFFFFF", "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" }, - "color" : "#FFFFFF", - "y" : 10, "align" : "right", "format" : "{point.y:.0f}", - "enabled" : "true" + "y" : 10, + "enabled" : "true", + "rotation" : -90 } } ], - "title" : { - "text" : "The Weekly Challenge Contributions [2019 - 2024]" - }, "xAxis" : { + "type" : "category", "labels" : { "style" : { "fontFamily" : "Verdana, sans-serif", "fontSize" : "13px" } - }, - "type" : "category" + } + }, + "title" : { + "text" : "The Weekly Challenge Contributions [2019 - 2024]" } } diff --git a/stats/pwc-language-breakdown.json b/stats/pwc-language-breakdown.json index bff59a5891..cfb1582c16 100644 --- a/stats/pwc-language-breakdown.json +++ b/stats/pwc-language-breakdown.json @@ -1,6 +1,8 @@ { - "xAxis" : { - "type" : "category" + "tooltip" : { + "pointFormat" : "Challenge {point.name}: {point.y:f}
", + "followPointer" : "true", + "headerFormat" : "" }, "chart" : { "type" : "column" @@ -14,13 +16,19 @@ } } }, - "legend" : { - "enabled" : "false" + "subtitle" : { + "text" : "Click the columns to drilldown the language breakdown. Last updated at 2024-03-05 12:27:05 GMT" + }, + "yAxis" : { + "title" : { + "text" : "Total Solutions" + } }, "drilldown" : { "series" : [ { "name" : "001", + "id" : "001", "data" : [ [ "Perl", @@ -34,10 +42,10 @@ "Blog", 12 ] - ], - "id" : "001" + ] }, { + "id" : "002", "name" : "002", "data" : [ [ @@ -52,11 +60,9 @@ "Blog", 10 ] - ], - "id" : "002" + ] }, { - "id" : "003", "data" : [ [ "Perl", @@ -71,9 +77,11 @@ 9 ] ], + "id" : "003", "name" : "003" }, { + "name" : "004", "id" : "004", "data" : [ [ @@ -88,12 +96,11 @@ "Blog", 10 ] - ], - "name" : "004" + ] }, { - "id" : "005", "name" : "005", + "id" : "005", "data" : [ [ "Perl", @@ -147,6 +154,7 @@ }, { "id" : "008", + "name" : "008", "data" : [ [ "Perl", @@ -160,11 +168,9 @@ "Blog", 12 ] - ], - "name" : "008" + ] }, { - "id" : "009", "data" : [ [ "Perl", @@ -179,9 +185,11 @@ 13 ] ], + "id" : "009", "name" : "009" }, { + "id" : "010", "name" : "010", "data" : [ [ @@ -196,12 +204,11 @@ "Blog", 11 ] - ], - "id" : "010" + ] }, { - "id" : "011", "name" : "011", + "id" : "011", "data" : [ [ "Perl", @@ -236,8 +243,6 @@ "id" : "012" }, { - "id" : "013", - "name" : "013", "data" : [ [ "Perl", @@ -251,9 +256,12 @@ "Blog", 13 ] - ] + ], + "name" : "013", + "id" : "013" }, { + "id" : "014", "name" : "014", "data" : [ [ @@ -268,10 +276,11 @@ "Blog", 15 ] - ], - "id" : "014" + ] }, { + "id" : "015", + "name" : "015", "data" : [ [ "Perl", @@ -285,12 +294,11 @@ "Blog", 15 ] - ], - "name" : "015", - "id" : "015" + ] }, { "name" : "016", + "id" : "016", "data" : [ [ "Perl", @@ -304,12 +312,11 @@ "Blog", 13 ] - ], - "id" : "016" + ] }, { - "id" : "017", "name" : "017", + "id" : "017", "data" : [ [ "Perl", @@ -327,6 +334,7 @@ }, { "id" : "018", + "name" : "018", "data" : [ [ "Perl", @@ -340,12 +348,9 @@ "Blog", 14 ] - ], - "name" : "018" + ] }, { - "id" : "019", - "name" : "019", "data" : [ [ "Perl", @@ -359,10 +364,13 @@ "Blog", 13 ] - ] + ], + "name" : "019", + "id" : "019" }, { "id" : "020", + "name" : "020", "data" : [ [ "Perl", @@ -376,11 +384,11 @@ "Blog", 13 ] - ], - "name" : "020" + ] }, { "name" : "021", + "id" : "021", "data" : [ [ "Perl", @@ -394,12 +402,9 @@ "Blog", 10 ] - ], - "id" : "021" + ] }, { - "id" : "022", - "name" : "022", "data" : [ [ "Perl", @@ -413,7 +418,9 @@ "Blog", 10 ] - ] + ], + "name" : "022", + "id" : "022" }, { "data" : [ @@ -434,8 +441,8 @@ "id" : "023" }, { - "id" : "024", "name" : "024", + "id" : "024", "data" : [ [ "Perl", @@ -452,8 +459,6 @@ ] }, { - "id" : "025", - "name" : "025", "data" : [ [ "Perl", @@ -467,10 +472,13 @@ "Blog", 12 ] - ] + ], + "id" : "025", + "name" : "025" }, { "name" : "026", + "id" : "026", "data" : [ [ "Perl", @@ -484,12 +492,9 @@ "Blog", 10 ] - ], - "id" : "026" + ] }, { - "id" : "027", - "name" : "027", "data" : [ [ "Perl", @@ -503,10 +508,11 @@ "Blog", 9 ] - ] + ], + "id" : "027", + "name" : "027" }, { - "name" : "028", "data" : [ [ "Perl", @@ -521,9 +527,12 @@ 9 ] ], + "name" : "028", "id" : "028" }, { + "name" : "029", + "id" : "029", "data" : [ [ "Perl", @@ -537,12 +546,9 @@ "Blog", 12 ] - ], - "name" : "029", - "id" : "029" + ] }, { - "id" : "030", "data" : [ [ "Perl", @@ -557,9 +563,12 @@ 10 ] ], - "name" : "030" + "name" : "030", + "id" : "030" }, { + "id" : "031", + "name" : "031", "data" : [ [ "Perl", @@ -573,9 +582,7 @@ "Blog", 9 ] - ], - "name" : "031", - "id" : "031" + ] }, { "id" : "032", @@ -596,7 +603,6 @@ ] }, { - "name" : "033", "data" : [ [ "Perl", @@ -611,7 +617,8 @@ 10 ] ], - "id" : "033" + "id" : "033", + "name" : "033" }, { "id" : "034", @@ -632,6 +639,8 @@ ] }, { + "id" : "035", + "name" : "035", "data" : [ [ "Perl", @@ -645,12 +654,9 @@ "Blog", 9 ] - ], - "name" : "035", - "id" : "035" + ] }, { - "id" : "036", "data" : [ [ "Perl", @@ -665,9 +671,11 @@ 11 ] ], + "id" : "036", "name" : "036" }, { + "id" : "037", "name" : "037", "data" : [ [ @@ -682,12 +690,9 @@ "Blog", 9 ] - ], - "id" : "037" + ] }, { - "id" : "038", - "name" : "038", "data" : [ [ "Perl", @@ -701,11 +706,11 @@ "Blog", 12 ] - ] + ], + "name" : "038", + "id" : "038" }, { - "id" : "039", - "name" : "039", "data" : [ [ "Perl", @@ -719,10 +724,13 @@ "Blog", 12 ] - ] + ], + "name" : "039", + "id" : "039" }, { "id" : "040", + "name" : "040", "data" : [ [ "Perl", @@ -736,11 +744,11 @@ "Blog",