Y
Hacker News
new
|
ask
|
show
|
jobs
by
cdelsolar
941 days ago
for i = 0 to n { for j = i to n { if n[j] > n[i] { swap(n[i], n[j] }}}
2 comments
btdmaster
940 days ago
Except that sorts the list in reverse:
https://tio.run/##Vc6xDsIwDATQPV9xYyJ5od2Qyo9UGYhIwFXkVlY68P...
(Also a subtle off-by-one error, it should be 0 to |n|-1 and i to |n|-1.)
link
cdelsolar
940 days ago
Thanks for catching the reverse. I was aware of the off by one but thought the “to” operator I invented would be exclusive of the second operand (kinda like range in Python) :)
link
sergiosgc
941 days ago
1 point for having a good reply. 100 points for doing it in code. Well done!
link
(Also a subtle off-by-one error, it should be 0 to |n|-1 and i to |n|-1.)