aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-027/simon-proctor/perl6/ch-1.p629
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-027/simon-proctor/perl6/ch-1.p6 b/challenge-027/simon-proctor/perl6/ch-1.p6
new file mode 100644
index 0000000000..6f68aeee29
--- /dev/null
+++ b/challenge-027/simon-proctor/perl6/ch-1.p6
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl6
+
+use v6;
+
+#| Takes 8 points for the lines (a,b) -> (c,d) and (p,q) -> (r,s)
+#| Outputs the intersection
+sub MAIN( Rat() \a, Rat() \b, Rat() \c, Rat() \d,
+ Rat() \p, Rat() \q, Rat() \r, Rat() \s ) {
+
+ my \a1 = d - b;
+ my \b1 = a - c;
+ my \c1 = a1*(a) + b1*(b);
+
+ my \a2 = s - q;
+ my \b2 = p - r;
+ my \c2 = a2*(p)+ b2*(q);
+
+ my \determinant = a1*b2 - a2*b1;
+
+ say "Lines ({a},{b}) -> ({c},{d}) and ({p},{q}) -> ({r},{s})";
+
+ if ( determinant == 0 ) {
+ say "Lines are parallel. No intersection";
+ } else {
+ my \x = (b2*c1 - b1*c2)/determinant;
+ my \y = (a1*c2 - a2*c1)/determinant;
+ say "Intersection at ({x},{y})";
+ }
+}