• BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    1 year ago

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

  • Allero@lemmy.today
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    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
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      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)

    • voldage@lemmy.world
      link
      fedilink
      arrow-up
      0
      arrow-down
      1
      ·
      1 year 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.