Skip to content

Instantly share code, notes, and snippets.

@waltman
Created July 31, 2017 18:43
Show Gist options
  • Save waltman/db93465065a2f1d8773ef6483acb8458 to your computer and use it in GitHub Desktop.
Save waltman/db93465065a2f1d8773ef6483acb8458 to your computer and use it in GitHub Desktop.
findMinMax.pl
#!/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