aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-101/yet-ebreo/perl/ch-2.pl24
1 files changed, 24 insertions, 0 deletions
diff --git a/challenge-101/yet-ebreo/perl/ch-2.pl b/challenge-101/yet-ebreo/perl/ch-2.pl
new file mode 100644
index 0000000000..f02c526d06
--- /dev/null
+++ b/challenge-101/yet-ebreo/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#! /usr/bin/perl
+
+use strict;
+use warnings;
+use feature qw(say);
+
+my @points = ( [0,1],
+ [2,0],
+ [-6,0]
+ );
+
+sub is_origin_in {
+ my (@p,$x) = @{+pop};
+ my $m = $p[0][1] * $p[2][0] - $p[0][0] * $p[2][1];
+ my $n = $p[0][0] * $p[1][1] - $p[0][1] * $p[1][0];
+
+ return (($m < 0) != ($n < 0)) ?
+ 0:
+ ( $x = $p[1][0] * $p[2][1] - $p[1][1] * $p[2][0] + $p[0][1] * ($p[2][0] - $p[1][0]) + $p[0][0] * ($p[1][1] - $p[2][1])) < 0 ?
+ ($m <= 0 && $m + $n >= $x) :
+ ($m >= 0 && $m + $n <= $x);
+}
+
+say is_origin_in (\@points) \ No newline at end of file