We would like to build a community for Small Basic programmers of any age who like to code. Everyone from total beginner to guru is welcome. Click here to register and share your programming journey!


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge 9 - Quick sort
#31
(translated by Google translator)

Hi all.  Shy
As I was falling asleep last night, this solution to the problem came to my mind:
Code:
'
' create a cell array
For i = 1 To 1024
  arr_cell[i] = Math.GetRandomNumber(1024)
EndFor

n_shift = 0
DisplayArray()

' put values into boxes
For i = 1 To 1024
  var_X = arr_cell[i]
  arr_box[var_X] = arr_box[var_X] + 1
EndFor

' return values ​​to cells
n_cellCursorPosition = 1

For n_boxCursorPosition = 1 To 1024
  If arr_box[n_boxCursorPosition] >= 1 Then
    For i = 1 To arr_box[n_boxCursorPosition]
      arr_cell[n_cellCursorPosition] = n_boxCursorPosition
      n_cellCursorPosition = n_cellCursorPosition + 1
    EndFor
  EndIf
EndFor

n_shift = 300
DisplayArray()
'----

'==========================================
' display the result on the screen
Sub DisplayArray
  n_size = 8
 
  GraphicsWindow.PenWidth = 1
  GraphicsWindow.PenColor = "DarkGray"
 
  For n_row = 0 To 31
    For n_column = 1 To 32
      var_X = arr_cell[n_row * 32 + n_column]
      n_green = Math.Floor(var_X / 128)
      n_red = var_X - (n_green * 128)
      GraphicsWindow.BrushColor = GraphicsWindow.GetColorFromRGB(n_red, n_green * 30, n_green * 30)
      GraphicsWindow.FillRectangle(n_column * n_size + n_shift, n_row * n_size + n_size, n_size, n_size)
    EndFor
  EndFor
EndSub

I don't know if you will be comfortable using the code if I put the code here. But, I feel sorry for wasting space on the server to release a program from the code editor.

It seems to me that it is no longer possible to sort an array faster Rolleyes . But, I haven't looked at other people's solutions yet and haven't received a solution from my Copilot.
Reply


Messages In This Thread
Challenge 9 - Quick sort - by litdev - 10-28-2024, 08:41 AM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 12:39 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 04:22 PM
RE: Challenge 9 - Quick sort - by z-s - 10-28-2024, 05:04 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 05:33 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 06:38 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 07:06 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 07:27 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 07:45 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 08:36 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 09:22 PM
RE: Challenge 9 - Quick sort - by Scout - 10-28-2024, 09:50 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-28-2024, 10:31 PM
RE: Challenge 9 - Quick sort - by z-s - 10-29-2024, 08:37 AM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 10-29-2024, 11:22 AM
RE: Challenge 9 - Quick sort - by litdev - 10-29-2024, 01:03 PM
RE: Challenge 9 - Quick sort - by z-s - 10-29-2024, 01:19 PM
RE: Challenge 9 - Quick sort - by Scout - 10-29-2024, 05:08 PM
RE: Challenge 9 - Quick sort - by AbsoluteBeginner - 10-30-2024, 09:56 AM
RE: Challenge 9 - Quick sort - by Scout - 10-30-2024, 08:43 PM
RE: Challenge 9 - Quick sort - by litdev - 10-30-2024, 10:47 PM
RE: Challenge 9 - Quick sort - by Scout - 10-31-2024, 09:21 PM
RE: Challenge 9 - Quick sort - by litdev - 11-05-2024, 03:14 PM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 11-18-2024, 12:29 AM
RE: Challenge 9 - Quick sort - by jrmrhrb00 - 11-18-2024, 12:54 PM

Forum Jump:


Users browsing this thread: 10 Guest(s)