Small Basic Forum
Challenge 9 - Quick sort - Printable Version

+- Small Basic Forum (https://litdev.uk/mybb)
+-- Forum: Small Basic (https://litdev.uk/mybb/forumdisplay.php?fid=1)
+--- Forum: Challenges (https://litdev.uk/mybb/forumdisplay.php?fid=5)
+--- Thread: Challenge 9 - Quick sort (/showthread.php?tid=152)

Pages: 1 2 3 4 5 6


Challenge 9 - Quick sort - litdev - 10-28-2024

Implement quicksort algorithm and sort 1000 random numbers.

Interesting to see if it's easier the usual way understanding the algorithm and writing the code or getting AI to do it for you?


RE: Challenge 9 - Quick sort - AbsoluteBeginner - 10-28-2024

This is a very interesting task.  Rolleyes
Plus I'll be able to compete against my Copilot.

Hello everyone, friends.  Shy


RE: Challenge 9 - Quick sort - jrmrhrb00 - 10-28-2024

QZVX574.000

Why doesn't this program work? It' just using LDArray.sort!

JR


RE: Challenge 9 - Quick sort - AbsoluteBeginner - 10-28-2024

(10-28-2024, 12:39 PM)jrmrhrb00 Wrote: QZVX574.000

Why doesn't this program work? It' just using LDArray.sort!

JR

Hello.
I think the program doesn't work because the LDArray.Sort() method is designed to work with arrays created by the LDArray.Create() method.
In my opinion, this method does not work with SB array.
Because these arrays are different from each other, the LDArray array works much faster than the SB array.


RE: Challenge 9 - Quick sort - jrmrhrb00 - 10-28-2024

AB,

I agree with you in that it has to be a ldArray.

So, here's the updated program. Still doesn't work.

JXNC572.000

JR


RE: Challenge 9 - Quick sort - AbsoluteBeginner - 10-28-2024

(10-28-2024, 04:22 PM)jrmrhrb00 Wrote: AB,

I agree with you in that it has to be a ldArray.

So, here's the updated program. Still doesn't work.

JXNC572.000

JR

One of the errors: status[i]=Math.GetRandomNumber(10)

There should be: LDArray.SetValue(status, i, Math.GetRandomNumber(10))


RE: Challenge 9 - Quick sort - z-s - 10-28-2024

I guess this is error Smile
Code : 
PHP Code:
'small basic array
For i = 1 To 10
name[i]=math.GetRandomNumber(10)
EndFor

'
creates ldArray from indices
status
=LDArray.CreateFromIndices(name)
TextWindow.WriteLine(status)

'loads ldarray with random numbers
For i = 1 To 10
status[i]=Math.GetRandomNumber(10)
EndFor

'
why does the below fail
result
=LDArray.Sort(status)
TextWindow.WriteLine(result)

'would give a listing of sorted numbers, but just shows them in their random order
For i = 1 To 10
TextWindow.WriteLine(status[i])
endfor 
I just don't run the code got it from mobile.
What results this show:
PHP Code:
result=LDArray.Sort(status)
TextWindow.WriteLine(result
And litdev extension api show for method:The input array is replaced by the sorted array
So after AB fix you have to make the last loop like this:
PHP Code:
For 1 To 10
TextWindow
.WriteLine(LDArray.GetValue(status,i))
endfor 



RE: Challenge 9 - Quick sort - jrmrhrb00 - 10-28-2024

AB,Z-S,

None of the suggested fixes worked. I guess I'll wait on LitDev. He is always good at figuring these things out.

JR


RE: Challenge 9 - Quick sort - AbsoluteBeginner - 10-28-2024

(10-28-2024, 05:33 PM)jrmrhrb00 Wrote: AB,Z-S,

None of the suggested fixes worked. I guess I'll wait on LitDev. He is always good at figuring these things out.

JR

This is because we haven't fixed all the bugs yet.
Can you paste the latest version of your code into your new message?


RE: Challenge 9 - Quick sort - jrmrhrb00 - 10-28-2024

AB, L-S,

I went back to basically the same code.

JR

JXNC572.000