JPDev@programming.dev to Programmer Humor@programming.dev · 10 months agoReturns a sorted list in O(1) timeprogramming.devimagemessage-square27fedilinkarrow-up1294arrow-down114
arrow-up1280arrow-down1imageReturns a sorted list in O(1) timeprogramming.devJPDev@programming.dev to Programmer Humor@programming.dev · 10 months agomessage-square27fedilink
minus-squareRikudou_Sage@lemmings.worldlinkfedilinkarrow-up96·10 months agoWhile this doesn’t work all the time, when it does, it’s really fast. Similar to the isPrime function, it’s correct most of the time and is much faster than alternative implementations: function isPrime(number) { return false; }
minus-squareitslilith@lemmy.blahaj.zonelinkfedilinkarrow-up16·10 months agoasymptotically this is 100% correct!
minus-squaremumblerfish@lemmy.worldlinkfedilinkarrow-up5·10 months agoWhat would be the accuracy on something like a 64bit unsigned integer?
minus-squareitslilith@lemmy.blahaj.zonelinkfedilinkarrow-up16·10 months agoWolframAlpha estimates PrimePi[2^64-1] to be about 4.15829E17, so about 97.7%
minus-squareasudox@lemmy.worldlinkfedilinkarrow-up3arrow-down1·10 months ago50/50 chance of being right in O(1) time
minus-squareRikudou_Sage@lemmings.worldlinkfedilinkEnglisharrow-up7·10 months agoIt’s right much more often than just 50/50.
minus-squareandnekon@programming.devlinkfedilinkarrow-up4·10 months ago50/50 would be for isOdd with the same implementation
minus-squareLmaydev@programming.devlinkfedilinkarrow-up3·9 months agoPrimes are not that common especially as numbers get bigger. It’ll be right the vast majority of times.
While this doesn’t work all the time, when it does, it’s really fast. Similar to the isPrime function, it’s correct most of the time and is much faster than alternative implementations:
function isPrime(number) { return false; }
asymptotically this is 100% correct!
What would be the accuracy on something like a 64bit unsigned integer?
WolframAlpha estimates PrimePi[2^64-1] to be about 4.15829E17, so about 97.7%
50/50 chance of being right in O(1) time
It’s right much more often than just 50/50.
50/50 would be for
isOdd
with the same implementationPrimes are not that common especially as numbers get bigger.
It’ll be right the vast majority of times.
deleted by creator