Skip to content

Instantly share code, notes, and snippets.

@tomcha
Created March 16, 2019 16:33
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tomcha/4bf4c345453a8b6a66bcce86193c6879 to your computer and use it in GitHub Desktop.
bubble_sort
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use DDP { deparse => 1 };
my @seeds;
for (1..100){
push(@seeds, int(rand(100)));
}
p @seeds;
my @endpoints = reverse(1..(scalar @seeds - 2));
for my $i (@endpoints){
for my $j (0..$i){
my $f = $seeds[$j];
my $s = $seeds[$j + 1];
if ($f > $s){
$seeds[$j] = $s;
$seeds[$j + 1] = $f;
}
}
}
p @seeds;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment