aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2025-08-08 01:18:35 +0100
committerGitHub <noreply@github.com>2025-08-08 01:18:35 +0100
commit46c1027805e77ed3e87e41fc85bc870c450ea226 (patch)
treeb3a2a8dd1d8d7f180c414bbdb3c7d66131a77bd9
parent5f137be7bf14bdaf27395faf9d2b04ae8b6e9587 (diff)
parentb4a035b3fb7a48f90a07474ed2cc49922644c6e3 (diff)
downloadperlweeklychallenge-club-46c1027805e77ed3e87e41fc85bc870c450ea226.tar.gz
perlweeklychallenge-club-46c1027805e77ed3e87e41fc85bc870c450ea226.tar.bz2
perlweeklychallenge-club-46c1027805e77ed3e87e41fc85bc870c450ea226.zip
Merge pull request #12480 from kjetillll/challenge-333-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-333/
-rw-r--r--challenge-333/kjetillll/perl/ch-1.pl19
-rw-r--r--challenge-333/kjetillll/perl/ch-2.pl22
2 files changed, 41 insertions, 0 deletions
diff --git a/challenge-333/kjetillll/perl/ch-1.pl b/challenge-333/kjetillll/perl/ch-1.pl
new file mode 100644
index 0000000000..40a087a317
--- /dev/null
+++ b/challenge-333/kjetillll/perl/ch-1.pl
@@ -0,0 +1,19 @@
+sub f {
+ my($x1, $y1) = @{ shift() };
+ my($x2, $y2) = @{ shift() };
+ my($x3, $y3) = @{ shift() };
+ $x1 * ($y2 - $y3) +
+ $x2 * ($y3 - $y1) +
+ $x3 * ($y1 - $y2)
+ ? 0 : !@_ ? 1 : f( [$x2, $y2], [$x3, $y3], @_ )
+}
+
+print pop(@$_) == f(@$_) ? "ok\n" : "err\n" for
+[ [2, 1], [2, 3], [2, 5] => 1 ],
+[ [1, 4], [3, 4], [10, 4] => 1 ],
+[ [0, 0], [1, 1], [2, 3] => 0 ],
+[ [1, 1], [1, 1], [1, 1] => 1 ],
+[ [1000000, 1000000], [2000000, 2000000], [3000000, 3000000] => 1 ],
+
+[ [2, 1], [2, 3], [2, 5], [2, 5e5] => 1 ],
+[ (map[300003+4*$_,-77*$_],1..100) => 1 ],
diff --git a/challenge-333/kjetillll/perl/ch-2.pl b/challenge-333/kjetillll/perl/ch-2.pl
new file mode 100644
index 0000000000..a83786244f
--- /dev/null
+++ b/challenge-333/kjetillll/perl/ch-2.pl
@@ -0,0 +1,22 @@
+
+sub f {
+ ( map { $_ || (0,0) } @_ )[ 0 .. $#_ ]
+}
+
+print "@{[f(@{$$_[0]})]}" eq "@{$$_[1]}" ? "ok\n" : "err\n" for
+
+[ [1, 0, 2, 3, 0, 4, 5, 0]
+ => [1, 0, 0, 2, 3, 0, 0, 4] ],
+
+
+[ [1, 2, 3],
+ => [1, 2, 3] ],
+
+[ [1, 2, 3, 0],
+ => [1, 2, 3, 0] ],
+
+[ [0, 0, 1, 2],
+ => [0, 0, 0, 0] ],
+
+[ [1, 2, 0, 3, 4],
+ => [1, 2, 0, 0, 3] ],