Upvote!
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
0x4E4F@infosec.pub to Programmer Humor@programming.devEnglish · 6 months ago

Not my problem sort

infosec.pub

message-square
70
fedilink
755

Not my problem sort

infosec.pub

0x4E4F@infosec.pub to Programmer Humor@programming.devEnglish · 6 months ago
message-square
70
fedilink
  • BatmanAoD@programming.dev
    link
    fedilink
    arrow-up
    151
    ·
    6 months ago

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

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      97
      ·
      6 months ago

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

      • frezik@midwest.social
        link
        fedilink
        arrow-up
        48
        ·
        6 months 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.

        • BatmanAoD@programming.dev
          link
          fedilink
          arrow-up
          44
          ·
          6 months ago

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

          • groet@feddit.org
            link
            fedilink
            English
            arrow-up
            13
            ·
            6 months 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.

            • MBM@lemmings.world
              link
              fedilink
              arrow-up
              9
              ·
              6 months ago

              Eh, trillion is a constant

          • FiskFisk33@startrek.website
            link
            fedilink
            arrow-up
            8
            ·
            6 months ago

            amortized O(0)

        • YonderEpochs@lemmy.world
          link
          fedilink
          arrow-up
          9
          ·
          6 months ago

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

          Well yeah just delete the pointer to it!

          • PoolloverNathan@programming.dev
            link
            fedilink
            arrow-up
            2
            ·
            6 months ago

            universe.take()

      • vithigar@lemmy.ca
        link
        fedilink
        arrow-up
        16
        ·
        6 months ago

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

        • db2@lemmy.world
          link
          fedilink
          arrow-up
          7
          ·
          6 months ago

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

      • frezik@midwest.social
        link
        fedilink
        arrow-up
        1
        ·
        6 months ago

        deleted by creator

    • Zaphod@discuss.tchncs.de
      link
      fedilink
      arrow-up
      25
      ·
      6 months ago

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

      • BatmanAoD@programming.dev
        link
        fedilink
        arrow-up
        5
        arrow-down
        1
        ·
        6 months ago

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

    • random72guy@lemmy.world
      link
      fedilink
      arrow-up
      17
      arrow-down
      1
      ·
      6 months 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.

      • BatmanAoD@programming.dev
        link
        fedilink
        arrow-up
        6
        ·
        6 months ago

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

    • SubArcticTundra@lemmy.ml
      link
      fedilink
      arrow-up
      13
      ·
      6 months ago

      What library are you using for that?

      • jcg@halubilo.social
        link
        fedilink
        arrow-up
        29
        ·
        edit-2
        6 months 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

        • Swedneck@discuss.tchncs.de
          link
          fedilink
          arrow-up
          8
          ·
          6 months ago

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

          • onlinepersona@programming.dev
            link
            fedilink
            arrow-up
            2
            arrow-down
            2
            ·
            edit-2
            6 months ago

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

            Anti Commercial-AI license

      • SkaveRat@discuss.tchncs.de
        link
        fedilink
        arrow-up
        11
        ·
        6 months ago

        In Python you just use

        import destroy_universe
        
    • frezik@midwest.social
      link
      fedilink
      arrow-up
      2
      ·
      6 months ago

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

Programmer Humor@programming.dev

programmer_humor@programming.dev

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: !programmer_humor@programming.dev

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
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 2.37K users / day
  • 4.7K users / week
  • 9.34K users / month
  • 17.8K users / 6 months
  • 1 local subscriber
  • 23.1K subscribers
  • 1.31K Posts
  • 43.1K Comments
  • Modlog
  • mods:
  • Feyter@programming.dev
  • adr1an@programming.dev
  • BurningTurtle@programming.dev
  • Pierre-Yves Lapersonne@programming.dev
  • BE: 0.19.6
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org