halubilo.social
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
@[email protected] to Programmer [email protected]English • 1 year ago

Not my problem sort

infosec.pub

message-square
70
fedilink
755

Not my problem sort

infosec.pub

@[email protected] to Programmer [email protected]English • 1 year ago
message-square
70
fedilink
  • @[email protected]
    link
    fedilink
    151•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.

    • @[email protected]
      link
      fedilink
      97•1 year ago

      Guaranteed to sort the list in nearly instantaneous time and with absolutely no downsides that are capable of objecting.

      • @[email protected]
        link
        fedilink
        48•1 year ago

        You still have to check that it’s sorted, which is O(n).

        We’ll also assume that destroying the universe takes constant time.

        • @[email protected]
          link
          fedilink
          44•1 year ago

          In the universe where the list is sorted, it doesn’t actually matter how long the destruction takes!

          • @[email protected]
            link
            fedilink
            English
            13•1 year ago

            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.

            • @[email protected]
              link
              fedilink
              9•1 year ago

              Eh, trillion is a constant

          • @[email protected]
            link
            fedilink
            8•1 year ago

            amortized O(0)

        • YonderEpochs
          link
          fedilink
          9•1 year ago

          We’ll also assume that destroying the universe takes constant time.

          Well yeah just delete the pointer to it!

          • @[email protected]
            link
            fedilink
            2•1 year ago

            universe.take()

      • @[email protected]
        link
        fedilink
        16•1 year ago

        Except you missed a bug in the “check if it’s sorted” code and it ends up destroying every universe.

        • @[email protected]
          link
          fedilink
          7•1 year ago

          There’s a bug in it now, that’s why we’re still here.

      • @[email protected]
        link
        fedilink
        1•1 year ago

        deleted by creator

    • @[email protected]
      link
      fedilink
      25•1 year ago

      The creation and destruction of universes is left as an exercise to the reader

      • @[email protected]
        link
        fedilink
        4•1 year ago

        Creation is easy, assuming the many-worlds interpretation of quantum mechanics!

    • NaN
      link
      fedilink
      16•1 year ago

      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.

      • @[email protected]
        link
        fedilink
        6•1 year ago

        Delete prior iterations of the loop in the same timeline? I’m not sure there’s anything in quantum mechanics to permit that…

    • @[email protected]
      link
      fedilink
      13•1 year ago

      What library are you using for that?

      • @jcgA
        link
        29•
        edit-2
        1 year ago

        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

        • @[email protected]
          link
          fedilink
          8•1 year ago

          that explains why it took god 7 days to make the universe

          • @[email protected]
            link
            fedilink
            1•
            edit-2
            1 year ago

            We still suffer from the runtime errors that could’ve been caught at compilation time.

            Anti Commercial-AI license

      • SkaveRat
        link
        fedilink
        11•1 year ago

        In Python you just use

        import destroy_universe
        
    • @[email protected]
      link
      fedilink
      2•1 year ago

      Since randomizing the list increases entropy, it could theoretically make your cpu cooler just before it destroys the universe.

Programmer [email protected]

[email protected]

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

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
  • 1.04K users / day
  • 3.93K users / week
  • 8.91K users / month
  • 18.3K users / 6 months
  • 27K subscribers
  • 1.84K Posts
  • 67.1K Comments
  • Modlog
  • mods:
  • Feyter
  • adr1an
  • @[email protected]
  • Pierre-Yves Lapersonne
  • BE: 0.19.3
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org