diff options
| -rw-r--r-- | challenge-027/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-027/paulo-custodio/README | 1 | ||||
| -rw-r--r-- | challenge-027/paulo-custodio/perl/ch-1.pl | 23 | ||||
| -rw-r--r-- | challenge-027/paulo-custodio/perl/ch-2.pl | 38 | ||||
| -rw-r--r-- | challenge-027/paulo-custodio/t/test-1.yaml | 5 | ||||
| -rw-r--r-- | challenge-027/paulo-custodio/t/test-2.yaml | 5 |
6 files changed, 74 insertions, 0 deletions
diff --git a/challenge-027/paulo-custodio/Makefile b/challenge-027/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-027/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-027/paulo-custodio/README b/challenge-027/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-027/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-027/paulo-custodio/perl/ch-1.pl b/challenge-027/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..e4b4feca3e --- /dev/null +++ b/challenge-027/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl + +# Challenge 027 +# +# Task #1 +# Write a script to find the intersection of two straight lines. The +# co-ordinates of the two lines should be provided as command line parameter. +# For example: +# +# The two ends of Line 1 are represented as co-ordinates (a,b) and (c,d). +# +# The two ends of Line 2 are represented as co-ordinates (p,q) and (r,s). +# +# The script should print the co-ordinates of point of intersection of the +# above two lines. + +use Modern::Perl; + +my($x1,$y1,$x2,$y2,$x3,$y3,$x4,$y4) = @ARGV; +my $D = ($x1-$x2)*($y3-$y4)-($y1-$y2)*($x3-$x4); +my $x = (($x1*$y2-$y1*$x2)*($x3-$x4)-($x1-$x2)*($x3*$y4-$y3*$x4))/$D; +my $y = (($x1*$y2-$y1*$x2)*($y3-$y4)-($y1-$y2)*($x3*$y4-$y3*$x4))/$D; +say sprintf("%.1f %.1f", $x, $y); diff --git a/challenge-027/paulo-custodio/perl/ch-2.pl b/challenge-027/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..8091076b58 --- /dev/null +++ b/challenge-027/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,38 @@ +#!/usr/bin/perl + +# Challenge 027 +# +# Task #2 +# Write a script that allows you to capture/display historical data. It could +# be an object or a scalar. For example +# +# my $x = 10; $x = 20; $x -= 5; +# +# After the above operations, it should list $x historical value in order. + +use Modern::Perl; + +{ + package LoggingScalar; + sub TIESCALAR { + my($class, $value) = @_; + return bless [$value], $class; + } + sub FETCH { + my($self) = @_; + return $self->[-1]; + } + sub STORE { + my($self, $value) = @_; + push @$self, $value; + } + sub show_hist { + my($self) = @_; + say join(" ", @$self); + } +} + +tie my $x, 'LoggingScalar', 10; +$x = 20; +$x -= 5; +tied($x)->show_hist(); diff --git a/challenge-027/paulo-custodio/t/test-1.yaml b/challenge-027/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..31ebb25d9b --- /dev/null +++ b/challenge-027/paulo-custodio/t/test-1.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: 15 10 49 25 29 5 32 32 + input: + output: 30.3 16.8 diff --git a/challenge-027/paulo-custodio/t/test-2.yaml b/challenge-027/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..78447f751a --- /dev/null +++ b/challenge-027/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: + input: + output: 10 20 15 |
