Created
May 9, 2022 15:02
-
-
Save hectorcorrea/9266607d3d47a1f54dac033746133287 to your computer and use it in GitHub Desktop.
Ruby version of "the simplest (and most surprising) sorting algorithm ever"
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
# Reference: https://arxiv.org/abs/2110.01111 | |
a = [1, 9, 100, 23, 4, 99, 500, 245, 77] | |
n = a.length-1 | |
puts "-- ORIGINAL --" | |
puts a | |
for i in 0..n do | |
for j in 0..n do | |
if a[i] < a[j] | |
# swap them | |
a[j], a[i] = a[i], a[j] | |
end | |
end | |
end | |
puts "-- SORTED --" | |
puts a | |
puts "------------" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment