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…
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.
I’m not sure there’s any guarantee that it will ever be sorted, since bit flips will be random and are just as likely to put it more out of order than more in order. Plus if there’s any error correction going on, it can cancel out bit flips entirely until up to a certain threshold.
Though I’m not sure if ECC (and other methods) write the corrected value back to memory or just correct the signals going to the core, so it’s possible they could still add up over time and overcome the second objection.
Those bitflips are probably more likely to skip the section erroneously than waiting for the array to be sorted.
Fair enough! But won’t they flip again to start the program?
Might also take a very long time (or a large amount of radiation).
import yhwh def interventionSort(unsortedList): sortedList = yhwh.pray( "Oh great and merciful Lord above, let thine glory shine upon yonder list!", unsortedList ) return sortedList
Camelcase in python, ew, a fundamentalist would do that
yhwh looking suspiciously like an LLM
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
They would see nothing wrong with it
Do you not understand federation yet? https://lemmy.ml/post/22259107/14814668
I prefer the one where you randomly sorting the array until all elements are in order. ( Bogosort )
Hello programmers…
I recently took a course that went through basic python, C, and C++.
I had a hard time implementing various forms of sorting functions by hand (these were exercises for exam study). Are there any resources you folks would recommend so that I can build a better grasp of sorting implementations and efficiency?
Skiena’s Algorithm design manual is very widely recommended for learning algorithms, I’ve also heard good things about A common sense guide to algorithms and data structures. Skiena’s also has video lectures on YouTube if you prefer videos.
From what I’ve seen, a common sense guide seems to be more geared towards newer programmers while Skiena assumes more experience. Consequently, Skiena goes into more depth while A common sense guide seems to be more focused on what you specifically asked for. algorithm design manual
Thank you, awesome! I will definitely check out this material :)
This is the algoritm I use at work.
Reminds me of quantum-bogosort: randomize the list; check if it is sorted. If it is, you’re done; otherwise, destroy this universe.
The creation and destruction of universes is left as an exercise to the reader
Creation is easy, assuming the many-worlds interpretation of quantum mechanics!
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!
universe.take()
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.
deleted by creator
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?
In Python you just use
import destroy_universe
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
that explains why it took god 7 days to make the universe
We still suffer from the runtime errors that could’ve been caught at compilation time.
Since randomizing the list increases entropy, it could theoretically make your cpu cooler just before it destroys the universe.
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.
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.
Oh yeah, I didn’t think about the time that it takes to check if it’s sorted. The sorting time is constant though
// portability
Gave me the giggles. I’ve helped maintain systems where this portable solution would have left everyone better off.
CosmicRaySort.
I wonder how many 2 item lists have been sorted that way IRL.
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 ✨