aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-11 00:26:13 +0100
committerGitHub <noreply@github.com>2025-08-11 00:26:13 +0100
commit2ea6d57ecd4b14cd71b4d1f6830e99afb98b1f31 (patch)
tree03e2b90079eccf9670f71224183aa8ec05df0584
parent7a5e59150341bdc829e96858c3ed9acea5f6f87c (diff)
parentb2f2472394f36e8ee33312521f0cdfb996c537cd (diff)
downloadperlweeklychallenge-club-2ea6d57ecd4b14cd71b4d1f6830e99afb98b1f31.tar.gz
perlweeklychallenge-club-2ea6d57ecd4b14cd71b4d1f6830e99afb98b1f31.tar.bz2
perlweeklychallenge-club-2ea6d57ecd4b14cd71b4d1f6830e99afb98b1f31.zip
Merge pull request #12496 from ysth/challenge-333-ysth
challenge 333 perl solutions
-rw-r--r--challenge-333/ysth/perl/ch-1.pl27
-rw-r--r--challenge-333/ysth/perl/ch-2.pl15
2 files changed, 42 insertions, 0 deletions
diff --git a/challenge-333/ysth/perl/ch-1.pl b/challenge-333/ysth/perl/ch-1.pl
new file mode 100644
index 0000000000..d36337a1b7
--- /dev/null
+++ b/challenge-333/ysth/perl/ch-1.pl
@@ -0,0 +1,27 @@
+use 5.040; # for true and false
+
+sub straight_line(@coordinates) {
+ if (@coordinates < 4 || @coordinates % 2) {
+ return @coordinates == 2;
+ }
+
+ my ($x0,$y0,$x1,$y1) = splice @coordinates, 0, 4;
+ # need to find a different second point to define the line
+ while ($x1 == $x0 && $y1 == $y0) {
+ ($x1,$y1) = splice @coordinates, 0, 2 or last;
+ }
+ while (my ($x,$y) = splice @coordinates, 0, 2) {
+ return false if ($y-$y0)*($x1-$x0) != ($x-$x0)*($y1-$y0);
+ }
+ return true;
+}
+
+sub main() {
+ my @inputs = @ARGV;
+
+ say straight_line(@inputs) ? 'true' : 'false';
+
+ return;
+}
+
+main() unless caller;
diff --git a/challenge-333/ysth/perl/ch-2.pl b/challenge-333/ysth/perl/ch-2.pl
new file mode 100644
index 0000000000..e623142e6c
--- /dev/null
+++ b/challenge-333/ysth/perl/ch-2.pl
@@ -0,0 +1,15 @@
+use 5.036;
+
+sub duplicate_zeros(@inputs) {
+ (map $_ || ($_,$_), @inputs)[0..$#inputs]
+}
+
+sub main() {
+ my @inputs = @ARGV;
+
+ say join ' ', duplicate_zeros(@inputs);
+
+ return;
+}
+
+main() unless caller;