codility/lib/CyclicRotation.pm

36 lines
706 B
Perl
Raw Permalink Normal View History

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.