aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-10-02 22:54:51 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-10-02 22:54:51 +0800
commitc1f9c3a1309d813f5fc706cb6af21eb9cf6658ac (patch)
tree5af47e989114ee5fbdd82d2a546e69d7d18ea883
parent394b06b4fa451926a2b239d3925ca29346819e02 (diff)
downloadperlweeklychallenge-club-c1f9c3a1309d813f5fc706cb6af21eb9cf6658ac.tar.gz
perlweeklychallenge-club-c1f9c3a1309d813f5fc706cb6af21eb9cf6658ac.tar.bz2
perlweeklychallenge-club-c1f9c3a1309d813f5fc706cb6af21eb9cf6658ac.zip
fix
-rwxr-xr-xchallenge-237/feng-chang/raku/ch-1.raku10
-rwxr-xr-xchallenge-237/feng-chang/raku/ch-1a.raku5
-rwxr-xr-xchallenge-237/feng-chang/raku/ch-2.raku5
-rwxr-xr-xchallenge-237/feng-chang/raku/test.raku29
4 files changed, 49 insertions, 0 deletions
diff --git a/challenge-237/feng-chang/raku/ch-1.raku b/challenge-237/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..3e4b04e828
--- /dev/null
+++ b/challenge-237/feng-chang/raku/ch-1.raku
@@ -0,0 +1,10 @@
+#!/bin/env raku
+
+unit sub MAIN(UInt:D $year, UInt:D $month, UInt:D $week-of-month, UInt:D $day-of-week);
+
+my $month_ = $month.fmt('%02d');
+my $dow01 = Date.new("{$year}-{$month_}-01").day-of-week;
+my $target = 1 + ($day-of-week - $dow01 + 7) % 7 + 7 * ($week-of-month - 1);
+put try {
+ Date.new("{$year}-{$month_}-{$target.fmt('%02d')}");
+} ?? $target !! 0;
diff --git a/challenge-237/feng-chang/raku/ch-1a.raku b/challenge-237/feng-chang/raku/ch-1a.raku
new file mode 100755
index 0000000000..018d31ccb4
--- /dev/null
+++ b/challenge-237/feng-chang/raku/ch-1a.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(UInt:D $year, UInt:D $month, UInt:D $week-of-month, UInt:D $day-of-week);
+
+put (1..31).grep({ Date.new("{$year}-{$month.fmt('%02d')}-{.fmt('%02d')}").day-of-week == $day-of-week })[$week-of-month - 1] // 0;
diff --git a/challenge-237/feng-chang/raku/ch-2.raku b/challenge-237/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..8279088ca3
--- /dev/null
+++ b/challenge-237/feng-chang/raku/ch-2.raku
@@ -0,0 +1,5 @@
+#!/bin/env raku
+
+unit sub MAIN(*@nums);
+
+put @nums.permutations.map((@nums Z< *).sum).max;
diff --git a/challenge-237/feng-chang/raku/test.raku b/challenge-237/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..dfa76c8be9
--- /dev/null
+++ b/challenge-237/feng-chang/raku/test.raku
@@ -0,0 +1,29 @@
+#!/bin/env raku
+
+# The Weekly Challenge 236
+use Test;
+
+sub pwc-test(Str:D $script, Bool :$deeply? = False, *@input) {
+ my ($expect, $assertion) = @input.splice(*-2, 2);
+ my $p = run $script, |@input, :out;
+ if $deeply {
+ is-deeply $p.out.slurp(:close).chomp.words.Bag, $expect, $assertion;
+ } else {
+ is $p.out.slurp(:close).chomp, $expect, $assertion;
+ }
+}
+
+# Task 1, Seize The Day
+pwc-test './ch-1.raku', |<2024 4 3 2>, 16, 'Seize The Day: (2024, 4, 3, 2) => 16';
+pwc-test './ch-1.raku', |<2025 10 2 4>, 9, 'Seize The Day: (2025, 10, 2, 4) => 9';
+pwc-test './ch-1.raku', |<2026 8 5 3>, 0, 'Seize The Day: (2026, 8, 5, 3) => 0';
+
+pwc-test './ch-1a.raku', |<2024 4 3 2>, 16, 'Seize The Day: (2024, 4, 3, 2) => 16';
+pwc-test './ch-1a.raku', |<2025 10 2 4>, 9, 'Seize The Day: (2025, 10, 2, 4) => 9';
+pwc-test './ch-1a.raku', |<2026 8 5 3>, 0, 'Seize The Day: (2026, 8, 5, 3) => 0';
+
+# Task 2, Maximise Greatness
+pwc-test './ch-2.raku', |<1 3 5 2 1 3 1>, 4, 'Maximise Greatness: (1, 3, 5, 2, 1, 3, 1) => 4';
+pwc-test './ch-2.raku', |<1 2 3 4>, 3, 'Maximise Greatness: (1, 2, 3, 4) => 3';
+
+done-testing;