Finding a random seed that solves a LeetCode problem (2023)

(mcognetta.github.io)

98 points | by mcyc 83 days ago

6 comments

  • porphyra 83 days ago
    Reminds me of this rock paper scissors bot that has a 59% win rate against other algorithms: https://rpscontest.com/entry/614005
    • bwestergard 83 days ago
      This is extremely funny. I'm assuming they just tried many seeds until one worked, to demonstrate the role of chance in scoring these programs?
      • porphyra 83 days ago
        Apparently they downloaded a bunch of the best bots at the time and tested locally to find a seed that performs the best.
        • ryan-c 83 days ago
          If I recall correctly, I downloaded all of them, then pruned any that appeared to have non-deterministic behaviour (for example, using random), then used the offline testing script[0] helpfully provided by the site.

          It was the first piece of code I put out that someone referred to as "art"[1].

          Some others that hit the HN front page over the years:

          https://news.ycombinator.com/item?id=10195358

          https://news.ycombinator.com/item?id=9516824

          https://news.ycombinator.com/item?id=26615938

          I also had wrote some code for my former employer containing the magic string "haha jit go brrr" that raised some eyebrows when someone reverse engineering the code noticed it. It was part of a routine to try to coax the JIT into optimizing the code soon on low end Android devices for performance reasons, but someone who didn't understand what the code was doing thought it was part of an exploit... :facepalm:

          0. https://rpscontest.com/rpsrunner.py

          1. https://rya.nc/threads/art-and-beauty.html

          • its-summertime 83 days ago
            > I also had wrote some code for my former employer containing the magic string "haha jit go brrr"

            https://iter.ca/post/reddit-whiteops/

            • ryan-c 83 days ago
              The code that checked for DRM support set the "distinctiveIdentifier" config option to "not-allowed" specifically to avoid being useful for tracking. Most of the stuff that people think is "fingerprinting" is just trying to confirm the browser is what it claims to be. It is (or was) tricky to make DRM work in chromium compiled from source.

              `!("a" == "a"[0])` just detects IE6/7, as they return undefined for "a"[0]: https://unspecified.wordpress.com/2008/06/15/portable-javasc...

              Here's the slide deck for a con talk I did a while back: https://rya.nc/files/A_nickel_tour_of_the_ad_fraud_ecosystem...

              I haven't worked there for a couple of years though.

            • lupire 82 days ago
              How is that related?
              • fragmede 82 days ago
                > Contains what appears to be a Javascript engine JIT exploit/bug, "haha jit go brrrrr" appears in a part of the code that appears to be doing something weird with math operations.
          • rdlw 83 days ago
            Here's the explanation from someone less wise but with a better memory: https://news.ycombinator.com/item?id=8441292

            :) the only extra bit of info there is that the seed was found by brute force over a few days

            • ryan-c 83 days ago
              ROFL. Good find. I'd forgotten I left it running that long, I thought it was probably just overnight. Nowadays when I want to brute force something like that, I just rent a couple hundred cores for an hour.

              (and pray to the gods I don't somehow leave the instances running by mistake)

          • adastra22 83 days ago
            > If I recall correctly, I…

            Only on HN does someone asks questions about an obscure cool thing and the original author enters the discussion. Thanks for the explanation.

            • ryan-c 83 days ago
              Imagine my surprise at opening the comments and seeing a reference to some obscure art I made a dozen years ago.
  • Xcelerate 83 days ago
    Haha, this is pretty funny. I immediately thought of Cantor's diagonal argument when I saw the question, but it makes me wonder — how long would it have taken me to solve the problem if I hadn't previously read about Cantor's argument in the context of Turing machines?

    Here's a variant: "Given a list of k LeetCode problems sourced from a bag of n unique tricks, generate a new LeetCode problem that utilizes a trick not found in the bag."

    I'm being facetious of course, but actually now I have an idea that we could create a bipartite graph mapping tricks to LeetCode problems. From there, given a willingness to memorize n tricks, we can compute the optimal bag of tricks to commit to memory in order to maximize the number of LeetCode problems quickly solvable during an interview, weighted by the probability of each problem's appearance.

    • fragmede 82 days ago
      Hilariously, you can plug that into ChatGPT and get a (new?) leetcode problem out.

      https://chatgpt.com/share/baf1c785-11dc-46d1-aed7-860cbc741f...

    • jrochkind1 83 days ago
      Cantor's diagonilization is something I think one would learn in most CS curricula, at least I did.

      Obviously Cantor was a genius, I would not expect most people, including myself, to come up with his argument themselves from scratch!

      • eru 83 days ago
        Yes. Cantors diagonalisation wasn't just a neat proof for an interesting theorem, but it made Cantor one of the few people to invent an entirely new class of proof technique. I'd give it a similar status to techniques like 'indirect proof' and 'induction'.
      • nitwit005 83 days ago
        I learned about that proof from a YouTube math video, rather than my Computer Science degree or minor in Mathematics.

        People expect genius in interviews all the time. They just don't realize that's what they're doing. They think what they're asking about is an obvious concept, forgetting that (insert renowned genius here) came up with the idea.

        • YZF 83 days ago
          I'd have thought group theory would be a required math course. This would also come up in Comp.Sci. complexity contexts and even in Calculus or mathematical logic contexts (I'm sure in many others I'm missing). Way back when this was a required first year course in the Comp.Sci./Math program I took.
          • nitwit005 82 days ago
            I suspect you are forgetting the possibility they just didn't cover that particular proof.
            • jrochkind1 82 days ago
              I also would have thought that it would be covered in a CS curriculum, as I said. it'snot just some random proof, but an important foundational one. (I don't think I "forgot a possibilty", I just thought it usually would).

              You are saying you took classes that covered logic, number theory, group theory, algorithmic complexity, discrete math, and calculus, and you are certain none of them covered this? Too bad, that is unfortunate! I'm glad you found it on your own! it's really neat!

        • gopher_space 82 days ago
          How many times have you been asked to rediscover the Fibonacci sequence and then make it useful to some stupid business?
    • zzigge 82 days ago
      That seems almost like the way people curate their Magic the Gathering decks.
  • RomanPushkin 83 days ago
    The same can be applied to a stock market. I am a big fan of looking into historical data, and I was using WealthLab for quite a while.

    One of the funniest things is when you find "strategy" that performs best over one year by making from 50 to 100 deals. But don't get fooled, it's just a random parameters, and when applied to the next year or years, you won't get these results, of course.

    So you're getting reliable results only when you can reproduce your success (no matter what it is) consistently.

    • deliveryboyman 83 days ago
      This does not speak to the randomness of markets. Only the ever changing nature of them.
      • eru 83 days ago
        In some sense, randomness is a modelling choice, not a statement about the underlying mechanism.

        Eg we wouldn't be able to tell whether stock prices are truly random (according to some distribution), or governed by a cryptographically secure pseudo random number generator.

        Another example: quantum mechanics is a fully deterministic theory. It's even linear, so we don't even get deterministic chaos like from Newtonian billiard balls or the Newtonian three body problem.

        But some popular interpretations of quantum mechanics like the Copenhagen Interpretation decide that they need to add randomness to make sense of QM's predictions.

        In contrast, some other interpretations like Many Worlds leave QM deterministic.

  • freediver 83 days ago
    Reminds me of LLMs, where the weights are the 'seed' that solves standard benchmark suite.
    • mcyc 83 days ago
      You may enjoy this article: https://arxiv.org/abs/2109.08203

      The author treats the seed as a hyperparameter and searches for the one that performs best for training a CV model.

  • b20000 83 days ago
    so when is the last time you used this in your code you write on a day to day basis?
  • hfjke 82 days ago
    [dead]