aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Shitov <mail@andreyshitov.com>2025-08-04 22:13:26 +0200
committerAndrew Shitov <mail@andreyshitov.com>2025-08-04 22:13:26 +0200
commit47179386d2c8614596eb2f8e2ee00488c4cf3531 (patch)
tree517bd55e6186e1f9484e68b1510d92e6bf34e7fc
parent1a22d3966095c3575bf3a3ac5fccd21df52755e5 (diff)
downloadperlweeklychallenge-club-47179386d2c8614596eb2f8e2ee00488c4cf3531.tar.gz
perlweeklychallenge-club-47179386d2c8614596eb2f8e2ee00488c4cf3531.tar.bz2
perlweeklychallenge-club-47179386d2c8614596eb2f8e2ee00488c4cf3531.zip
Solution Task 2 Week 333 in Raku by @ash
-rw-r--r--challenge-333/ash/raku/ch-1.raku25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-333/ash/raku/ch-1.raku b/challenge-333/ash/raku/ch-1.raku
new file mode 100644
index 0000000000..e176d3dddd
--- /dev/null
+++ b/challenge-333/ash/raku/ch-1.raku
@@ -0,0 +1,25 @@
+# Task 1 of the Weekly Challenge 333
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-333/#TASK1
+
+say is-straight-line([2, 1], [2, 3], [2, 5]); # True
+say is-straight-line([1, 4], [3, 4], [10, 4]); # True
+say is-straight-line([0, 0], [1, 1], [2, 3]); # False
+say is-straight-line([1, 1], [1, 1], [1, 1]); # True
+say is-straight-line([1000000, 1000000], [2000000, 2000000], [3000000, 3000000]); # True
+
+
+sub is-straight-line(**@points) {
+ return True if @points.elems < 3;
+
+ my ($x0, $y0) = @points.shift;
+ my ($x1, $y1) = @points.shift;
+
+ my $dx = $x1 - $x0;
+ my $dy = $y1 - $y0;
+
+ for @points -> $point {
+ return False if $dy * ($point[0] - $x0) != $dx * ($point[1] - $y0);
+ }
+
+ return True;
+}