Add code, pod and tests for CyclicRotation
This commit is contained in:
parent
51afbeae72
commit
019657c95a
6 changed files with 173 additions and 5 deletions
36
lib/CyclicRotation.pm
Normal file
36
lib/CyclicRotation.pm
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package CyclicRotation;
|
||||
|
||||
use Modern::Perl;
|
||||
|
||||
sub solution {
|
||||
my ($A, $K) = @_;
|
||||
|
||||
die "You must provide an array reference to rotate" unless defined $A;
|
||||
die "You must provide an number of rotations" unless defined $K;
|
||||
my @A = @$A;
|
||||
|
||||
push(@A, splice(@A, 0, $K));
|
||||
|
||||
|
||||
return \@A;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
__END__
|
||||
|
||||
=pod
|
||||
|
||||
=encoding utf8
|
||||
|
||||
=head1 NAME
|
||||
|
||||
CyclicRotation - Given an array reference $A and integer $K rotate the array A a number of times specified by K.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
cyclic_rotation.pl $array $integer
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This module is used to exercise CyclicRotation.pm. It takes one array ref and one integer as input. It returns the array ref rotated the amount of times indicated by the integer.
|
||||
Loading…
Add table
Add a link
Reference in a new issue