From 47179386d2c8614596eb2f8e2ee00488c4cf3531 Mon Sep 17 00:00:00 2001 From: Andrew Shitov Date: Mon, 4 Aug 2025 22:13:26 +0200 Subject: Solution Task 2 Week 333 in Raku by @ash --- challenge-333/ash/raku/ch-1.raku | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 challenge-333/ash/raku/ch-1.raku 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; +} -- cgit