Skip to content

Instantly share code, notes, and snippets.

@hectorcorrea
Created May 9, 2022 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hectorcorrea/9266607d3d47a1f54dac033746133287 to your computer and use it in GitHub Desktop.
Save hectorcorrea/9266607d3d47a1f54dac033746133287 to your computer and use it in GitHub Desktop.
Ruby version of "the simplest (and most surprising) sorting algorithm ever"
# 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