this post was submitted on 08 Nov 2024
743 points (98.2% liked)

Programmer Humor

19557 readers
854 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] mavu@discuss.tchncs.de 3 points 6 days ago (1 children)

Wait, that's exactly how i tidy up my kitchen!

[–] 0x4E4F@infosec.pub 1 points 6 days ago

On a long enough time scale, yes, it will get tidy.

[–] BatmanAoD@programming.dev 149 points 1 week ago (5 children)

Reminds me of quantum-bogosort: randomize the list; check if it is sorted. If it is, you're done; otherwise, destroy this universe.

[–] xmunk@sh.itjust.works 96 points 1 week ago (3 children)

Guaranteed to sort the list in nearly instantaneous time and with absolutely no downsides that are capable of objecting.

[–] frezik@midwest.social 48 points 1 week ago (2 children)

You still have to check that it's sorted, which is O(n).

We'll also assume that destroying the universe takes constant time.

[–] BatmanAoD@programming.dev 43 points 1 week ago (2 children)

In the universe where the list is sorted, it doesn't actually matter how long the destruction takes!

[–] groet@feddit.org 13 points 1 week ago (1 children)

It actually takes a few trillion years but its fine because we just stop considering the "failed" universes because they will be gone soon™ anyway.

[–] MBM@lemmings.world 8 points 1 week ago

Eh, trillion is a constant

[–] FiskFisk33@startrek.website 8 points 1 week ago

amortized O(0)

[–] Benjaben@lemmy.world 9 points 1 week ago (1 children)

We'll also assume that destroying the universe takes constant time.

Well yeah just delete the pointer to it!

load more comments (1 replies)
[–] vithigar@lemmy.ca 16 points 1 week ago (1 children)

Except you missed a bug in the "check if it's sorted" code and it ends up destroying every universe.

[–] db2@lemmy.world 7 points 1 week ago

There's a bug in it now, that's why we're still here.

load more comments (1 replies)
[–] Zaphod@discuss.tchncs.de 25 points 1 week ago (1 children)

The creation and destruction of universes is left as an exercise to the reader

load more comments (1 replies)
[–] random72guy@lemmy.world 17 points 1 week ago (1 children)

Instead of destroying the universe, can we destroy prior, failed shuffle/check iterations to retain o(1)? Then we wouldn't have to reload all of creation into RAM.

[–] BatmanAoD@programming.dev 6 points 1 week ago

Delete prior iterations of the loop in the same timeline? I'm not sure there's anything in quantum mechanics to permit that...

[–] SubArcticTundra@lemmy.ml 13 points 1 week ago (2 children)

What library are you using for that?

[–] jcg@halubilo.social 29 points 1 week ago* (last edited 1 week ago) (1 children)

is-sorted and a handful of about 300 other npm packages. Cloning the repo and installing takes about 16 hours but after that you're pretty much good for the rest of eternity

[–] Swedneck@discuss.tchncs.de 8 points 1 week ago (1 children)

that explains why it took god 7 days to make the universe

load more comments (1 replies)
[–] SkaveRat@discuss.tchncs.de 11 points 1 week ago

In Python you just use

import destroy_universe
load more comments (1 replies)
[–] state_electrician@discuss.tchncs.de 135 points 1 week ago (3 children)

My favorite is StalinSort. You go through the list and eliminate all elements which are not in line.

[–] pyre@lemmy.world 53 points 1 week ago* (last edited 1 week ago) (6 children)

you should post this on lemmy.ml

[–] affiliate@lemmy.world 33 points 1 week ago

it would be a pretty funny post for the full 5 minutes it would last until it got stalin sorted out of lemmy.ml

load more comments (5 replies)
load more comments (2 replies)
[–] ChaoticNeutralCzech@feddit.org 51 points 1 week ago (1 children)
[–] MajorHavoc@programming.dev 32 points 1 week ago
// portability

Gave me the giggles. I've helped maintain systems where this portable solution would have left everyone better off.

[–] TheTechnician27@lemmy.world 40 points 1 week ago (1 children)
load more comments (1 replies)
[–] Swedneck@discuss.tchncs.de 31 points 1 week ago* (last edited 1 week ago) (4 children)
import yhwh  

def interventionSort(unsortedList):
    sortedList = yhwh.pray(
    "Oh great and merciful Lord above, let thine glory shine upon yonder list!", 
    unsortedList
    )  
    return sortedList
[–] nucleative@lemmy.world 1 points 6 days ago

Where's this yhwh library, can I install it with pip? Seems like it could have potential for some of my projects.

[–] porous_grey_matter@lemmy.ml 10 points 1 week ago

Camelcase in python, ew, a fundamentalist would do that

load more comments (2 replies)
[–] Allero@lemmy.today 27 points 1 week ago (6 children)

The most beautiful thing about this program is that it would work.

Various bit flips will once lead to all numbers being in the correct order. No guarantee the numbers will be the same, though...

[–] ProgrammingSocks@pawb.social 3 points 1 week ago (2 children)

Not necessarily. I don't have the numbers in front if me, but there is actually a probability that, past that point, something is so unlikely that you can consider it to be impossible (I.e. will never happen within the lifetime of the universe)

[–] TriflingToad@sh.itjust.works 1 points 6 days ago

screw the universe we be flippin' 😎🏄‍♀️

[–] Dyskolos@lemmy.zip 1 points 6 days ago

Yet... The chance is never zero 😁

[–] fallingcats@discuss.tchncs.de 8 points 1 week ago (2 children)

Those bitflips are probably more likely to skip the section erroneously than waiting for the array to be sorted.

load more comments (2 replies)
[–] Midnitte@beehaw.org 7 points 1 week ago

Might also take a very long time (or a large amount of radiation).

[–] Zoomboingding@lemmy.world 6 points 1 week ago

Reminds me of a program in Homestuck. It's code that iterates until the author/universe dies, then executes some unknown code. The coding language is ~ath, or TilDeath.

load more comments (2 replies)
[–] 1984@lemmy.today 25 points 1 week ago (1 children)

This is the algoritm I use at work.

[–] 0x4E4F@infosec.pub 1 points 6 days ago

Everyone does... it's funny how it eventually works.

[–] fluckx@lemmy.world 24 points 1 week ago* (last edited 6 days ago) (1 children)

I prefer the one where you randomly sort the array until all elements are in order. ( Bogosort )

load more comments (1 replies)
[–] lemmydividebyzero@reddthat.com 19 points 1 week ago (1 children)
[–] Ephera@lemmy.ml 34 points 1 week ago

I hear, it actually significantly increases the chance of the miracle occurring when you pass the array into multiple threads. It's a very mysterious algorithm.

[–] iAvicenna@lemmy.world 14 points 1 week ago (1 children)

you can also call it quantum sort since there is non zero probability that it will sort itself by random flips

[–] Comment105@lemm.ee 5 points 1 week ago (1 children)

It would actually have happened an infinite amount of times already, if either the universe is infinite, or there are infinite universes.

load more comments (1 replies)
[–] aeharding@vger.social 13 points 1 week ago* (last edited 1 week ago) (1 children)

Shameless plug for my sort lib

edit: Looking at my old code it might be time to add typescript, es6 and promises to make it ✨  p r o d u c t i o n   r e a d y  ✨

load more comments (1 replies)
[–] 1boiledpotato@sh.itjust.works 8 points 1 week ago (1 children)

And the time complexity is only O(1)

[–] voldage@lemmy.world 14 points 1 week ago (1 children)

I don't think you can check if array of n elements is sorted in O(1), if you skip the check though and just assume it is sorted now (have faith), then the time would be constant, depending on how long you're willing to wait until the miracle happens. As long as MTM (Mean Time to Miracle) is constant, the faithfull miracle sort has O(1) time complexity, even if MTM is infinite. Faithless miracle sort has at best the complexity of the algorithm that checks if the array is sorted.

Technically you can to down to O(0) if you assume all array are always sorted.

load more comments (1 replies)
load more comments
view more: next ›