Skip to content

Instantly share code, notes, and snippets.

@S2
Created May 29, 2018 08:45
Show Gist options
  • Save S2/2e36a8ce65447a9e5067d16a8a71b84d to your computer and use it in GitHub Desktop.
Save S2/2e36a8ce65447a9e5067d16a8a71b84d to your computer and use it in GitHub Desktop.
BubbleSort
#!/usr/bin/env perl
use 5.16.2;
use strict;
use warnings;
use utf8;
use String::Random qw/random_regex/;
use Test::More;
for(1..20){
my $i = [map{0 + random_regex '\d{3}'}1..150];
my $s = 1;
while($s){
$s = 0;
for(0..@$i - 2){
if($i->[$_] > $i->[$_ + 1]){
@$i[$_ , $_ + 1] = @$i[$_ + 1 , $_];
$s = 1
}
}
}
is_deeply [sort {$a <=> $b}@$i] , $i;
}
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment