Created
July 31, 2017 18:43
-
-
Save waltman/db93465065a2f1d8773ef6483acb8458 to your computer and use it in GitHub Desktop.
findMinMax.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use feature ":5.10"; | |
use feature 'signatures'; | |
no warnings "experimental::signatures"; | |
use Algorithm::Combinatorics qw(permutations); | |
my @ints = @ARGV; | |
my ($min, $max) = findMinMax(\@ints); | |
say "min = $min"; | |
say "max = $max"; | |
sub findMinMax($ints) { | |
my $min = "inf"; | |
my $max = "-inf"; | |
my $iter = permutations(\@ints); | |
while (my $p = $iter->next) { | |
my $x = join "", @$p; | |
$min = $x if $x < $min; | |
$max = $x if $x > $max; | |
} | |
return ($min, $max); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment