• Allero@lemmy.today
    link
    fedilink
    arrow-up
    14
    ·
    8 hours 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…

    • Buddahriffic@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      2 minutes ago

      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.

    • 🔍🦘🛎@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      19 minutes ago

      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.

  • Swedneck@discuss.tchncs.de
    link
    fedilink
    arrow-up
    21
    ·
    edit-2
    9 hours ago
    import yhwh  
    
    def interventionSort(unsortedList):
        sortedList = yhwh.pray(
        "Oh great and merciful Lord above, let thine glory shine upon yonder list!", 
        unsortedList
        )  
        return sortedList
    
  • TheOakTree@lemm.ee
    link
    fedilink
    arrow-up
    6
    arrow-down
    1
    ·
    8 hours ago

    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?

    • 90s_hacker@reddthat.com
      link
      fedilink
      arrow-up
      6
      ·
      edit-2
      8 hours ago

      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

      A common sense guide

  • fluckx@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    11 hours ago

    I prefer the one where you randomly sorting the array until all elements are in order. ( Bogosort )

    • Ephera@lemmy.ml
      link
      fedilink
      arrow-up
      31
      ·
      12 hours ago

      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.

  • BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    125
    ·
    17 hours ago

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

    • voldage@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      8 hours 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.

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      27
      ·
      16 hours ago
      // portability
      

      Gave me the giggles. I’ve helped maintain systems where this portable solution would have left everyone better off.