aboutsummaryrefslogtreecommitdiff
path: root/challenge-078/jeongoon/perl/ch-2.pl
blob: fbf01989e90d85e14866a5941e22a15f7adb71dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/env perl

# tested with: raku ch-1.raku 7 4 2 6 3 / 1 3 4

use strict; use warnings;
use v5.26;
use List::MoreUtils qw(firstidx);

sub leftRotate ($$) {
    my ($A, $B) = @_;
    ($A->$#* > 0 and $B->$#* > 0) or return ($A);
    map {  if ( $_ > $A->$#* ) { warn "$_: out of range: do not change";  $A }
           else { [ $A->@[ $_ ..$A->$#*, 0..$_-1 ] ] }
    } $B->@*;
}

my $sep_pos = firstidx { !/[+-]*[1-9][0-9]*/ } @ARGV;
my @answer = leftRotate( [ @ARGV[ 0.. ($sep_pos-1) ] ],
                         [ @ARGV[ $sep_pos+1 .. $#ARGV ] ] );

say "(@$_)" for @answer;