Skip to content

Instantly share code, notes, and snippets.

@yanick
Created August 1, 2015 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanick/77f676b8dd8b319ead4d to your computer and use it in GitHub Desktop.
Save yanick/77f676b8dd8b319ead4d to your computer and use it in GitHub Desktop.
use strict;
use warnings;
sub hashgregate(&@){
my $sub = shift;
my %agg;
push @{$agg{$sub->($_)}}, $_ for @_;
return wantarray ? %agg : \%agg;
}
my $first_divisors = hashgregate { my $i = 2; $i++ while $_ % $i; $i } 2..100;
use Data::Printer;
p $first_divisors;
@genehack
Copy link

genehack commented Aug 1, 2015

"Hashregate"?! You are a bad person.

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