Wait, that's exactly how i tidy up my kitchen!
Programmer Humor
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
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
On a long enough time scale, yes, it will get tidy.
Reminds me of quantum-bogosort: randomize the list; check if it is sorted. If it is, you're done; otherwise, destroy this universe.
Guaranteed to sort the list in nearly instantaneous time and with absolutely no downsides that are capable of objecting.
You still have to check that it's sorted, which is O(n).
We'll also assume that destroying the universe takes constant time.
In the universe where the list is sorted, it doesn't actually matter how long the destruction takes!
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.
Eh, trillion is a constant
amortized O(0)
We'll also assume that destroying the universe takes constant time.
Well yeah just delete the pointer to it!
Except you missed a bug in the "check if it's sorted" code and it ends up destroying every universe.
There's a bug in it now, that's why we're still here.
The creation and destruction of universes is left as an exercise to the reader
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.
Delete prior iterations of the loop in the same timeline? I'm not sure there's anything in quantum mechanics to permit that...
What library are you using for that?
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
In Python you just use
import destroy_universe
My favorite is StalinSort. You go through the list and eliminate all elements which are not in line.
you should post this on lemmy.ml
it would be a pretty funny post for the full 5 minutes it would last until it got stalin sorted out of lemmy.ml
// portability
Gave me the giggles. I've helped maintain systems where this portable solution would have left everyone better off.
import yhwh
def interventionSort(unsortedList):
sortedList = yhwh.pray(
"Oh great and merciful Lord above, let thine glory shine upon yonder list!",
unsortedList
)
return sortedList
Where's this yhwh library, can I install it with pip? Seems like it could have potential for some of my projects.
Camelcase in python, ew, a fundamentalist would do that
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...
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)
screw the universe we be flippin' 😎🏄♀️
Yet... The chance is never zero 😁
Those bitflips are probably more likely to skip the section erroneously than waiting for the array to be sorted.
Might also take a very long time (or a large amount of radiation).
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.
This is the algoritm I use at work.
Everyone does... it's funny how it eventually works.
I prefer the one where you randomly sort the array until all elements are in order. ( Bogosort )
Is it thread safe?
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.
you can also call it quantum sort since there is non zero probability that it will sort itself by random flips
It would actually have happened an infinite amount of times already, if either the universe is infinite, or there are infinite universes.
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 ✨
And the time complexity is only O(1)
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.