Skip to content

Instantly share code, notes, and snippets.

@EdGuiness
Last active December 15, 2015 17:20
Show Gist options
  • Select an option

  • Save EdGuiness/5296102 to your computer and use it in GitHub Desktop.

Select an option

Save EdGuiness/5296102 to your computer and use it in GitHub Desktop.
playing with sort
sub findRemainder {
map {return $_[0] % ($_[1] || 1) } @_ = sort { $b <=> $a } @_;
}
print findRemainder(142,1000),"\n";
print findRemainder(1000,142),"\n";
print findRemainder(1000,0),"\n"
@MidLifeXis
Copy link

This won't work either. map() only takes one element at a time.

How about ordering your terms (not that I necessarily agree with your definition, but...)

    my ($min, $max) = sort { $a <=> $b } @_;
    return $max % ( $min || 1 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment