this post was submitted on 08 Nov 2024
5 points (100.0% liked)

Programmer Humor

22295 readers
1938 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 2 years ago
MODERATORS
 
top 15 comments
sorted by: hot top controversial new old
[–] [email protected] 2 points 5 months ago (1 children)

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

[–] [email protected] 0 points 5 months ago* (last edited 5 months ago) (1 children)

you should post this on lemmy.ml

[–] [email protected] 1 points 5 months 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

[–] [email protected] 1 points 5 months ago (2 children)

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

[–] [email protected] 1 points 5 months ago (1 children)

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

[–] [email protected] 0 points 5 months ago (1 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.

[–] [email protected] 1 points 5 months ago (1 children)

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

[–] [email protected] 0 points 5 months 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.

[–] [email protected] 1 points 5 months ago

Eh, trillion is a constant

[–] [email protected] 0 points 5 months ago (1 children)

What library are you using for that?

[–] [email protected] 0 points 5 months ago* (last edited 5 months 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

[–] [email protected] 0 points 5 months ago (1 children)

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

[–] [email protected] -1 points 5 months ago* (last edited 5 months ago)

We still suffer from the runtime errors that could've been caught at compilation time.

Anti Commercial-AI license

[–] [email protected] 0 points 5 months ago (1 children)

And the time complexity is only O(1)

[–] [email protected] -1 points 5 months ago

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.