diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-12-27 09:27:35 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-12-27 09:27:35 +0000 |
| commit | 047bdb45082c8a3362dcc3c2f4a0d02c7afb880a (patch) | |
| tree | c70626ef7d77421ae85daccb651be693469f8f9c | |
| parent | 584a4bba6121cfdb8e977bd807449e61d3d8c13c (diff) | |
| parent | 5068359650ab2bf9dd9fa71e8273ed17a13177d6 (diff) | |
| download | perlweeklychallenge-club-047bdb45082c8a3362dcc3c2f4a0d02c7afb880a.tar.gz perlweeklychallenge-club-047bdb45082c8a3362dcc3c2f4a0d02c7afb880a.tar.bz2 perlweeklychallenge-club-047bdb45082c8a3362dcc3c2f4a0d02c7afb880a.zip | |
Merge pull request #3074 from stuart-little/stuart-little_027
1st commit on 027
| -rw-r--r-- | challenge-027/stuart-little/README | 1 | ||||
| -rwxr-xr-x | challenge-027/stuart-little/raku/ch-1.p6 | 15 | ||||
| -rwxr-xr-x | challenge-027/stuart-little/raku/ch-2.p6 | 26 |
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-027/stuart-little/README b/challenge-027/stuart-little/README new file mode 100644 index 0000000000..78439907de --- /dev/null +++ b/challenge-027/stuart-little/README @@ -0,0 +1 @@ +Solutions by Stuart Little diff --git a/challenge-027/stuart-little/raku/ch-1.p6 b/challenge-027/stuart-little/raku/ch-1.p6 new file mode 100755 index 0000000000..e511f70557 --- /dev/null +++ b/challenge-027/stuart-little/raku/ch-1.p6 @@ -0,0 +1,15 @@ +#!/usr/bin/env perl6 +use v6; + +# run as <script> <eight space-separated coordinates: a b c d p q r s for points (a,b), (c,d), etc.> + +use Math::Matrix; + +sub intersect(($a,$b,$c,$d,$p,$q,$r,$s)) { + ($d-$b)*($r-$p) == ($c-$a)*($s-$q) && return "The lines have equal slope: no unique intersection."; + my $A = Math::Matrix.new([[$b-$d,$c-$a],[$q-$s,$r-$p]]); + my $v=Math::Matrix.new([[$b*$c-$a*$d],[$q*$r-$p*$s]]); + return $A.inverted.dot-product($v); +} + +say intersect(@*ARGS[0..7]) diff --git a/challenge-027/stuart-little/raku/ch-2.p6 b/challenge-027/stuart-little/raku/ch-2.p6 new file mode 100755 index 0000000000..a994b643b5 --- /dev/null +++ b/challenge-027/stuart-little/raku/ch-2.p6 @@ -0,0 +1,26 @@ +#!/usr/bin/env perl6 +use v6; + +# run as <script> +# +# learned of STORE from +# https://rosettacode.org/wiki/History_variables#Raku + +class HistVar { + has @!history; + has $!var handles <Str gist>; + method STORE($val) is rw { + $!var.defined && push @!history, $!var; + say ((@!history) ?? ("was: {@!history}; ") !! ""), "is now: {$val}"; + $!var = $val; + } +} + +my @x is HistVar.new; + +@x=1; +@x=2; +@x=3; +@x=4; + +say "current: {@x}"; |
