Path: csiph.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.arch Subject: Re: Optimization by programmers Date: Tue, 06 Oct 2026 02:53:26 -0700 Organization: A noiseless patient Spider Lines: 47 Message-ID: <86a4orm9yh.fsf@linuxsc.com> References: <1177fdi$26ea4$1@dont-email.me> <6aa5876f.783937@news.eternal-september.org> <2026Sep12.201446@mips.complang.tuwien.ac.at> <6aa6172e.15711625@news.eternal-september.org> <2026Sep13.162747@mips.complang.tuwien.ac.at> <118h4cj$fi2a$1@dont-email.me> <118ltsc$26ss6$1@dont-email.me> <2026Sep19.175649@mips.complang.tuwien.ac.at> <118odha$31okp$1@dont-email.me> <86a4pct2oj.fsf@linuxsc.com> <119q3q8$36790$2@paganini.bofh.team> <8633unnhed.fsf@linuxsc.com> <11a19rf$3u6ge$1@paganini.bofh.team> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Tue, 06 Oct 2026 09:53:27 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1888870"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/pq89Nj8+oRO+hWZ3hFM1mn7AWT6VYShY="; posting-host="0b1fc18b52208379029243b7b311a32b" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:wtemaJsMZWcnDMlvVUsK3jhNG/Q= sha1:oVrRb47yEA/X4ROpa4wTUtb2xm0= sha256:yyq5EWiHZvEIULw1pExVHX9Q0fM+rIWT7Mjrg2Uwbks= sha1:VOABXLR9ySRTSYl18hJdugl9rcA= sha256:9+bdXv/fHsJd1xLO/MzuSJ/VpjVfKFxhINwccsthGY4= Xref: csiph.com comp.arch:118493 antispam@fricas.org (Waldek Hebisch) writes: > Tim Rentsch wrote: > >> antispam@fricas.org (Waldek Hebisch) writes: >> >>> Tim Rentsch wrote: >>> >>>> Thomas Koenig writes: >>>> >>>>> Bubblesort is the worst of non-joke sorting algorithms, see >>>>> the quote from Numerical Recipes... >>>> >>>> For people who don't like bubble sort, or for inclusion in a set >>>> of benchmarks, I suggest the following recently discovered >>>> sorting algorithm (written in C-ish pseudocode): >>>> >>>> void >>>> baffle_sort( unsigned n, int *elements ){ >>>> for( unsigned i = 0; i < n; i++ ){ >>>> for( unsigned j = 0; j < n; j++ ){ >>>> if( elements[i] < elements[j] ){ >>>> /* exchange elements[i] and elements[j] */ >>>> } >>>> } >>>> } >>>> } >>>> >>>> (Disclaimer: not original.) [...] >> I am making no claim that this sort would be a good choice if >> one wanted an efficient algorithm. Surely no one would choose >> it on that basis. That's not what makes it interesting. > > Probably the most interestiong thing about it is that it actually > sorts. That it actually sorts is I think the most surprising thing. What I found most interesting is how it sorts or why it sorts. It took me a while to understand what makes it work. It is difficult, for example, to write invariants for this code that can be used to establish the conclusion that sorting actually takes place. A better name than baffle_sort() might be least_transparent_sort(). But that would ruin the surprise. ;)