79321602

Date: 2025-01-01 12:42:53
Score: 1
Natty:
Report link

Just do a truncated selection sort?

In QB64PE BASIC (just because we can) B-) ...

For i = 1 to m
    For j = i to Ubound(array)
        If array(j) < array(i) Then Swap array(j), array(i)
    Next j
Next i

You now have the smallest m items from array() in the first m positions.

I just implemented this in QB64PE (again, because why not?) to find the 10 smallest elements from an array of 27,100 integers, and it took just on 1 microsecond on an M3Max MBP.

Reasons:
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Low reputation (1):
Posted by: Chris Cole