aboutsummaryrefslogtreecommitdiff
path: root/challenge-115/arne-sommer/perl/largest-multiple-perl
blob: c2dce1668d59ba1ad8806c9a123dfa9a0ddc66f9 (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
26
27
28
29
#! /usr/bin/env perl

use strict;
use warnings;
use feature 'say';
use Getopt::Long;
use Algorithm::Combinatorics 'permutations';

my $verbose = 0;

GetOptions("verbose" => \$verbose);

my @all;

for my $list (permutations(\@ARGV))
{
  my @candidate = @$list;
  my $value     = join("", @candidate);

  next unless $value =~ /[02468]$/;

  push(@all, $value);
}

@all = reverse sort @all;

say ": " . join(", ", @all) if $verbose && @all;

say $all[0] if $all[0] && $all[0] != 0;