
Worstsort - pplonski86
https://byorgey.wordpress.com/2019/02/16/worstsort/
======
kccqzy
I'll give it a try at defining the author's intuition of "doesn’t cheat" in
the sense that it is always "making real progress". I'll define it as every
intermediate value that is generated in the computation is eventually
consumed. If a function, say, computes Ackermann(5,5) and throws away the
result and then starts the actual sorting process, then the Ackermann(5,5) is
unused and would be considered cheating. In a sense we can draw a data-flow
diagram of the computation and everything has at least one outgoing edge,
except perhaps the final output.

~~~
XMPPwocky
Problem is we can define a function mix(a, b) which intermingles two arguments
and produces a new value dependent on both- for example, sha256(a.concat(b)).

Then we can take any randomized algorithm and, for its random values, use
mix(real_rng.random(), Ackermann(5, 5)).

------
hyperpape
Another “don’t cheat” intuition is “you can’t statically know that a function
call prior to the final result produces the correct answer”.

This fails that criterion, as you can just throw away all the calls except
badsort 0.

My criterion isn’t well defined, because what you can statically know isn’t
well defined, but I know a cheater when I see one :)

------
conistonwater
Reminds me a little of _reluctant search_ from _Pessimal Algorithms and
Simplexity Analysis_
([http://www.bowdoin.edu/~ltoma/teaching/cs231/fall13/Material...](http://www.bowdoin.edu/~ltoma/teaching/cs231/fall13/Material/broder86pessimal.pdf))

------
tluyben2
Are there competitions for this? If not, I think there should be; designing
the worst possible, but provably terminating and finite and non cheating (as
in the author his definition which I think is a good one) versions of
algorithms. The proof has to be provided by the author ofcourse.

~~~
praptak
There's the mathematical competition to define the largest precisely defined
number, i.e. "largest number defined by humans so far, plus one" is not ok,
but "largest finite number of cells visited by Turing machines of 7 states on
an initially zeroed tape" is ok. It's obviously about finding new tricks
rather than rehashing the existing ones.

It seems like the tricks from this competition would be reusable for the
slowest algorithm competition.

------
lelf
So

    
    
      sort ≡ head ∘ sort ∘ permutations
    

I wonder if there is some neat (and totally useless) algorithm for _sort_
using that info.

------
ddebernardy
When wondering what's the point in trying to find bad sort algorithms, I shed
a few tears thinking about a few StackOverflow questions in its early days
where a programming beginner would ask for basic algorithm implementations and
a few mischievous answerers would suggest things like boggle sort.

~~~
nicoburns
[https://gkoberger.github.io/stacksort/](https://gkoberger.github.io/stacksort/)

------
ginko
Would a Haskell implementation of the second step (recursively call badsort
and pick the first) actually exhaust all permutations of permutations before
picking the first item, or would this have O(n) (or at least less than O(n!))
complexity due to lazy evaluation?

~~~
majewsky
The foldl in `badSort 0` has to evaluate its entire argument list. As far as I
can see, this behavior propagates through to all functions shown in the
article since they all call `badSort 0` eventually.

~~~
gowld
It's foldr, not fold. That's what makes it consume absurd stack space,
creating a stack of thunks of length (n-factorial-iterated-k-times, including
the nested towers of folders inside each element) before it can use any
laziness to shortcut the actual comparisons applied by `insert`.

It creates the whole monolithic expression with all the parenthesis in
pessimal positions, forcing all the comparisons in the wrong order (back to
front, aka least-significant-bits first), which makes it impossible to use the
short circuiting of lexicographical comparisons.

------
benj111
Surely worstsort would be

While list not sorted { Random(list) }

?

~~~
lelf

      for x in 3 1 2 5 4; do (sleep $x; echo $x) & done

~~~
xaedes
I think that is equivalent to selection sort: You put all numbers into the
scheduler which periodically checks all scheduled threads and selects the one
which timer elapsed, i.e. it sequentially selects the scheduled tasks with
increasing timer duration value.

------
sometimesijust
The use of "foldr insert []" makes this redundant nonsense.

~~~
Hackbraten
I disagree. The scientifically interesting thing is that we can have such
exploding complexity, while at the same time every step of the algorithm still
actively works towards a solution.

