aboutsummaryrefslogtreecommitdiff
path: root/challenge-101/arne-sommer/perl/ch-2.pl
blob: aab2d92c5e61d394fe5e36c8f2715fddc709540d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#! /usr/bin/env perl

use strict;
use warnings;
use feature 'say';
use feature 'signatures';

no warnings "experimental::signatures";

die "Specify 6 or 8 values" unless @ARGV == 6 || @ARGV == 8;

my ($x1, $y1, $x2, $y2, $x3, $y3, $x, $y) = @ARGV;

$x = 0 unless defined $x;
$y = 0 unless defined $y;

my $ABC = area($x1, $y1, $x2, $y2, $x3, $y3);
my $PBC = area($x,  $y,  $x2, $y2, $x3, $y3);
my $PAC = area($x1, $y1, $x,  $y,  $x3, $y3); 
my $PAB = area($x1, $y1, $x2, $y2, $x,  $y); 

($ABC == $PBC + $PAC + $PAB) ? say 1 : say 0;

sub area($x1, $y1, $x2, $y2, $x3, $y3) 
{ 
  return abs( ($x1 * ($y2 - $y3) + $x2 * ($y3 - $y1) + $x3 * ($y1 - $y2) ) / 2); 
}