+ 2

Challenge #0

I noticed there aren't really any challenges in this app to apply your knowledge to. So I'll post some regular challengers for beginners and see if it catches on. I think you all should post some challenges too just to test each other out. Without further ado... Create code that sorts out the numbers in an array in ascending order WITHOUT the use of the sort function. And no, you can't use sorting functions from other modules. The array to sort is arr = [48,3,24,1,3,3,7] You have unlimited time to give an answer so feel free to take your time. I am looking forward to see some answers. Have fun!

3rd Jul 2016, 4:33 PM
Gershon Fosu
Gershon Fosu - avatar
4 Answers
+ 1
xD not quite what I was looking for. What if there were a thousand values in the array. Would you manually change a thousand positions? :p None the less, it works for the testcase I specified. Try making something that sorts arrays of any length.
3rd Jul 2016, 6:58 PM
Gershon Fosu
Gershon Fosu - avatar
+ 1
here's one, for example: arr=[48, 3, 24, 1, 3, 3, 7] for i in range(len(arr)): for j in range(len(arr)): if arr[i]<arr[j]: arr[i],arr[j]=arr[j],arr[i] print(arr) To those who are new to programming, there are at least six more ways (algorithms) to sort a list. try finding it yourself! Thought I'll leave this example as a reference!
4th Jul 2016, 3:16 AM
Jesse P Francis
Jesse P Francis - avatar
0
# sort list by manually change of index positions arr = [48, 3, 24, 1, 3, 3, 7] arr[0] = 1 arr[1] = 3 arr[2] = 3 arr[3] = 3 arr[4] = 7 arr[5] = 24 arr[6] = 48 print(arr) # result of print arr = [1, 3, 3, 3, 7, 24, 48]
3rd Jul 2016, 6:48 PM
Benneth Yankey
Benneth Yankey - avatar
0
That's a good idea Gershon Fosu! Post some other if you want.
4th Jul 2016, 6:55 PM
Leonardo Riglietti
Leonardo Riglietti - avatar