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