Skip to content

Instantly share code, notes, and snippets.

@salva
Last active August 29, 2015 14:10
Show Gist options
  • Save salva/b402c9ed3936b43c82fc to your computer and use it in GitHub Desktop.
Save salva/b402c9ed3936b43c82fc to your computer and use it in GitHub Desktop.
Mi solution to Ovid puzzle...
use strict;
use warnings;
my @a = ( [ 'b', 'c', 'f' ],
[ 'a', 'd' ],
[ 'c', 'd', 'e' ] );
my $last_ix = -1;
my %ixs;
my @b = map {
my @out;
$out[$ixs{$_} //= ++$last_ix] = $_ for @$_;
\@out;
} @a;
$#$_ = $last_ix for @b;
use Data::Dumper;
print Dumper \@b;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment