Given an array in random order try to sort the array by just shuffling the values. Once the array is sorted print out how many iterations ran. This is also known as bogosort. I'd recommend keeping your array length to 10 or less as the average number of runs for 10 is over 36 million.
Comments:
Lasharn - 12 years ago
Maybe a bit longer than it needs to be but here is my Java solution. I also had it timed because why not? :)
Gotta love bogosort.
reply permalink
Max Burstein - 12 years ago
lol nice. What kind of times were you seeing?
reply permalink
Lasharn - 12 years ago
It varied quite a bit (no surprises there since it's bogosort). Times were between 1-3 seconds.
When I add just 1 extra integer to the list (to make it size 11) this increased significantly to around 25-30 seconds. I wouldn't have the patience to add more.
reply permalink
Aaron Frase - 12 years ago
Here's my python solution.
reply permalink
Nick Krichevsky - 12 years ago
Did it with recursion in C++
reply permalink
Dustin S - 12 years ago
Here is my solution in go. The main function runs a 1000 trials of bogosort on lists of sizes 2-10.
If you are interested, I put the data from my experiments in a spreadsheet, and create some graphs. LINK
reply permalink