aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2023-12-04 15:43:12 +0800
committer冯昶 <fengchang@novel-supertv.com>2023-12-04 15:43:12 +0800
commit4ac02978fd0732a7fcc61a9def95e1e08100e4c9 (patch)
treef228cc7e17b207480600ac711863c488e9bb9e27
parent1b0f0c9cf0a1295b8bf9bef8d902f9a351120785 (diff)
downloadperlweeklychallenge-club-4ac02978fd0732a7fcc61a9def95e1e08100e4c9.tar.gz
perlweeklychallenge-club-4ac02978fd0732a7fcc61a9def95e1e08100e4c9.tar.bz2
perlweeklychallenge-club-4ac02978fd0732a7fcc61a9def95e1e08100e4c9.zip
challenge 246, raku solutions
-rwxr-xr-xchallenge-246/feng-chang/raku/ch-1.raku3
-rwxr-xr-xchallenge-246/feng-chang/raku/ch-2.raku8
-rwxr-xr-xchallenge-246/feng-chang/raku/test.raku21
3 files changed, 32 insertions, 0 deletions
diff --git a/challenge-246/feng-chang/raku/ch-1.raku b/challenge-246/feng-chang/raku/ch-1.raku
new file mode 100755
index 0000000000..6e18559070
--- /dev/null
+++ b/challenge-246/feng-chang/raku/ch-1.raku
@@ -0,0 +1,3 @@
+#!/bin/env raku
+
+.put for (1..49).pick(6);
diff --git a/challenge-246/feng-chang/raku/ch-2.raku b/challenge-246/feng-chang/raku/ch-2.raku
new file mode 100755
index 0000000000..90fef1869d
--- /dev/null
+++ b/challenge-246/feng-chang/raku/ch-2.raku
@@ -0,0 +1,8 @@
+#!/bin/env raku
+
+unit sub MAIN(*@ints where +* == 5);
+
+my Rat \m = (@ints[2]² - @ints[1] * @ints[3]) / (@ints[0] * @ints[2] - @ints[1]²);
+my Rat \q = (@ints[0] * @ints[3] - @ints[1] * @ints[2]) / (@ints[0] * @ints[2] - @ints[1]²);
+
+put m.Int == m && q.Int == q && @ints[4] == m * @ints[2] + q * @ints[3];
diff --git a/challenge-246/feng-chang/raku/test.raku b/challenge-246/feng-chang/raku/test.raku
new file mode 100755
index 0000000000..961095cb1a
--- /dev/null
+++ b/challenge-246/feng-chang/raku/test.raku
@@ -0,0 +1,21 @@
+#!/bin/env raku
+
+# The Weekly Challenge 246
+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 2, Linear Recurrence of Second Order
+pwc-test './ch-2.raku', |<1 1 2 3 5>, 'True', 'Linear Recurrence of Second Order: (1, 1, 2, 3, 5) => True';
+pwc-test './ch-2.raku', |<4 2 4 5 7>, 'False', 'Linear Recurrence of Second Order: (1, 1, 2, 3, 5) => False';
+pwc-test './ch-2.raku', |<4 1 2 -3 8>, 'True', 'Linear Recurrence of Second Order: (4, 1, 2, -3, 8) => True';
+
+done-testing;