aboutsummaryrefslogtreecommitdiff
path: root/challenge-220/john-horner/perl/ch-2.pl
blob: 82782c330a4456a5c1f548773267c5e52d8938b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use v5.10;
use strict;
use warnings;

my @ints = ( 2, 7, 4, 1, 8, 1, 8 );

my @sorted_ints = reverse sort @ints;

while ( scalar(@sorted_ints) > 1 ) {
    @sorted_ints = reverse sort @sorted_ints;
    my ( $x, $y ) = splice( @sorted_ints, 0, 2 );
    push( @sorted_ints, $x - $y ) if $x != $y;
}
say( scalar(@sorted_ints) == 1 ? @sorted_ints : 0 );