From df4aee15abcc46f8b2844b7ba035b45afa0ff31e Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 15 Sep 2020 13:26:46 +0200 Subject: Perl solutions for Week 78 --- challenge-078/abigail/Part2/solution.pl | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 challenge-078/abigail/Part2/solution.pl (limited to 'challenge-078/abigail/Part2/solution.pl') 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__ -- cgit