diff options
| author | 冯昶 <seaker@qq.com> | 2020-09-21 14:20:42 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2020-09-21 14:20:42 +0800 |
| commit | bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb (patch) | |
| tree | 877181cfde26b706346d3468269e4674d75da772 /challenge-078/abigail/Part2/solution.pl | |
| parent | ec09b571a6f2186fec8870a071a8d5d38596c850 (diff) | |
| parent | 5ac16ac7e9826137e0da5597e954f4992c66205d (diff) | |
| download | perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.gz perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.tar.bz2 perlweeklychallenge-club-bca0c362c212fc0dadc5ed7d9a5e4fa1aece4bfb.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-078/abigail/Part2/solution.pl')
| -rwxr-xr-x | challenge-078/abigail/Part2/solution.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-078/abigail/Part2/solution.pl b/challenge-078/abigail/Part2/solution.pl new file mode 100755 index 0000000000..80e8f4907d --- /dev/null +++ b/challenge-078/abigail/Part2/solution.pl @@ -0,0 +1,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__ |
