aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-05 12:11:10 +0000
committerGitHub <noreply@github.com>2024-03-05 12:11:10 +0000
commit5135ca89f43ed6d20f4414d28507a68980de1a82 (patch)
tree9e0451a05935d62c8a28aee6a2469e32bbd9cbcf
parentfdaa82fafabe11c7b18757d0177e595e8696fb8a (diff)
parent3d41fe40bd74fa7980f814f698b782204c1e3a3d (diff)
downloadperlweeklychallenge-club-5135ca89f43ed6d20f4414d28507a68980de1a82.tar.gz
perlweeklychallenge-club-5135ca89f43ed6d20f4414d28507a68980de1a82.tar.bz2
perlweeklychallenge-club-5135ca89f43ed6d20f4414d28507a68980de1a82.zip
Merge pull request #9697 from andemark/challenge-259
Challenge 259 Solutions (Raku)
-rw-r--r--challenge-259/mark-anderson/raku/ch-1.raku55
-rw-r--r--challenge-259/mark-anderson/raku/ch-2.raku29
2 files changed, 83 insertions, 1 deletions
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..09272b6c72
--- /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 { '{%' <ID> <KeyVal>* '%}' }
+ token ID { \w+ }
+ token Key { \w+ }
+ token Quoted { '\"' <[\w\s]>+ '\"' }
+ token Unquoted { <[\w\s]>+ }
+ token Val { '"' [<Quoted> || <Unquoted> || '\\' ]+ '"' || \d+ }
+ rule KeyVal { <Key> '=' <Val> }
+}
+
+sub parse-line($s)
+{
+ my %h;
+ my %fields;
+ my $m = Ch2.parse($s);
+
+ %h<name> = ~$m<ID>;
+ %fields{~.<Key>} = ~.<Val> for $m<KeyVal>;
+ %h<fields> = %fields;
+
+ return %h
+}