Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
29
Task/Vector/Perl/vector.pl
Normal file
29
Task/Vector/Perl/vector.pl
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use v5.36;
|
||||
|
||||
package Vector;
|
||||
use Moose;
|
||||
use overload '+' => \&add,
|
||||
'-' => \&sub,
|
||||
'*' => \&mul,
|
||||
'/' => \&div,
|
||||
'""' => \&stringify;
|
||||
|
||||
has 'x' => (is =>'rw', isa => 'Num', required => 1);
|
||||
has 'y' => (is =>'rw', isa => 'Num', required => 1);
|
||||
|
||||
sub add ($a, $b, $) { Vector->new( x => $a->x + $b->x, y => $a->y + $b->y) }
|
||||
sub sub ($a, $b, $) { Vector->new( x => $a->x - $b->x, y => $a->y - $b->y) }
|
||||
sub mul ($a, $b, $) { Vector->new( x => $a->x * $b, y => $a->y * $b) }
|
||||
sub div ($a, $b, $) { Vector->new( x => $a->x / $b, y => $a->y / $b) }
|
||||
sub stringify ($self, $, $) { '(' . $self->x . ',' . $self->y . ')' }
|
||||
|
||||
package main;
|
||||
|
||||
my $a = Vector->new(x => 5, y => 7);
|
||||
my $b = Vector->new(x => 2, y => 3);
|
||||
say "a: $a";
|
||||
say "b: $b";
|
||||
say "a+b: ",$a+$b;
|
||||
say "a-b: ",$a-$b;
|
||||
say "a*11: ",$a*11;
|
||||
say "a/2: ",$a/2;
|
||||
Loading…
Add table
Add a link
Reference in a new issue