aboutsummaryrefslogtreecommitdiff
path: root/challenge-078/abigail/Part2/solution.pl
blob: 80e8f4907d9b7e7daf22420dff071a3ceaa19f6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/opt/perl/bin/perl

#
# Exercise:
# 
#   You are given array @A containing positive numbers and @B containing
#   one or more indices from the array @A.
#   Write a script to left rotate @A so that the number at the first index
#   of @B becomes the first element in the array. Similary, left rotate @A
#   again so that the number at the second index of @B becomes the first
#   element in the array.
#

#
# We will be reading the arrays from STDIN -- @A is one the first
# line, @B is on the second line.
#

use 5.032;

use strict;
use warnings;
no  warnings 'syntax';

use experimental 'signatures';

#
# Read @A and @B
#
chomp (my @A = split / / => scalar <>);
chomp (my @B = split / / => scalar <>);

#
# Print the rotations.
#
foreach my $index (@B) {
    local $, = " ";
    say @A [$index .. @A - 1, 0 .. $index - 1];
}


__END__