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 - 11 years, 1 month 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 - 11 years, 1 month ago
lol nice. What kind of times were you seeing?
reply permalink
Lasharn - 11 years, 1 month 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 - 11 years, 1 month ago
Here's my python solution.
reply permalink
Nick Krichevsky - 11 years, 1 month ago
Did it with recursion in C++
reply permalink
Dustin S - 11 years, 1 month 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