-2
The Golf (re)Sort
Everyone is sorting arrays these days, and so do we at our day jobs. But we like to go out golfing. When we do, we sure like to take our time. It is important to have a stress free experience.
Since we like golfing so much, we have decided to make a sorting algorithm that will let us stay away from the desk as much as possible. We decided to make Golf (re)Sort, a sorting algorithm that takes as time long as possible to complete. This way we can spend more time doing what we like the most, golfing.
The task is easy: Sort an array of integers using an algorithm that takes as long time, and has as high O-notation, as possible.
The rules:
- The algorithm must be deterministic. Thus you may not use randomness in the algorithm (so no bogosort)
- You may not use any un-productive operations or loops. Eg.:
sleep 2
,for i<n; i++ {/*no-op*/}
,Open("www.the_internet.com").download
. Every operation needs to bring you closer to the goal of a sorted list. An example would be to simply reverse the array for no other reason than reversing the array to increase the Ω-notation.
Provide:
- Name of the language
- The code
- An explanation to the approach + Ω(Big-Omega)-notation (lower bound).
Scoring:
Scoring will be done by looking at the Ω-runtime. The higher the better.
Example:
Language: Ruby
Code:
a = [6,9,7,5,7,90,9,6,4,32,9,7,4,223]
sorted = []
while a.count > 0
min = [Float::INFINITY, -1]
a.each_with_index do |e,i|
min = [e,i] if e < min[0]
end
sorted << min[0]
a.delete_at(min[1])
end
puts sorted.to_s
This is a variation on selection sort which have runtime of Ω(n^2). It is slow because it scans the array for the lowest value, then pushes that to the result array. It then deletes the value from the original array and starts over.
1It should be Big-Omega instead of Big-O, since e.g. mergesort is in O(n!). – fabian – 2014-07-21T23:09:04.400
1
You should make it more clear in your question that the score is based on the algorithmic complexity of the answers. http://stackoverflow.com/a/12338937/1275256
– gxtaillon – 2014-07-22T00:30:44.5572This a a code-bowling problem, except with algorithmic complexity rather than number of characters. I suspect it will run into the same pitfalls. You need to be more precise with what you consider a useless operation, and what "closer" means in "Every operation needs to bring you closer to the goal of a sorted list." – xnor – 2014-07-22T04:02:58.100
@fabian You'r right. It should be lower bound. – Automatico – 2014-07-22T06:46:47.513
There is no quicker learning than when you "did something wrong" on SO or one of it's sister-sites. – Automatico – 2014-07-22T06:53:47.267
@gxtaillon I am considering scoring by time it takes to calculate on a given set of input on my machine, just for consistency and easier comparison. It would change the "course" of the question a bit since slow languages then would be preferred. What do you think of that? – Automatico – 2014-07-22T06:56:02.233
1There's one in a [code-trolling] question that has a C sorting program of O(n!...!) with the factorial repeated n times. Can't find it. – Ming-Tang – 2014-07-22T06:57:39.703
1
A fair few of the answers to http://codegolf.stackexchange.com/q/20478/194 could be reposted as is, so this is at best borderline for being a dupe.
– Peter Taylor – 2014-07-22T08:40:42.020Started a meta question about [changing the win] condition(http://meta.codegolf.stackexchange.com/).
– Automatico – 2014-07-22T09:57:37.487