Created
May 21, 2017 17:50
-
-
Save andrewsolomon/dae97235cd67cbb0a979fa21e069ddf6 to your computer and use it in GitHub Desktop.
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/perl | |
use strict; | |
use warnings; | |
use Data::Dump 'pp'; | |
use feature 'say'; | |
sub array_intersection { | |
my ($ra_x, $ra_y) = @_; | |
my @intersection; | |
foreach my $x (@$ra_x) { | |
foreach my $y (@$ra_y) { | |
if ($x == $y) { | |
push @intersection, $x; | |
} | |
} | |
} | |
my @sorted = sort(@intersection); | |
return \@sorted; | |
} | |
my $ra_first = [1,2,3,4,5,6]; | |
my $ra_second = [2,4,6,8,10]; | |
my $ra_intersection = array_intersection($ra_first, $ra_second); | |
say "The intersection of ".pp( $ra_first )." and ".pp($ra_second)." is ". | |
pp($ra_intersection); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment