aboutsummaryrefslogtreecommitdiff
path: root/challenge-307/sgreen/perl/ch-1.pl
blob: 45cf2e8a67f931b008dc87f19cc10089168eb79f (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
#!/usr/bin/env perl

use strict;
use warnings;
use feature 'say';
use experimental 'signatures';

sub main (@ints) {
    # Sort the lists numerically
    my @sorted_ints = sort { $a <=> $b } @ints;
    my @differences = ();

    foreach my $idx ( 0 .. $#ints ) {
        if ( $ints[$idx] != $sorted_ints[$idx] ) {
            # If the value in the original list and sorted list at this
            #  position is different, add it to the differences list.
            push @differences, $idx;
        }
    }

    # Return the list
    say '(', join( ', ', @differences ), ')';
}

main(@ARGV);