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

98 points
1/20/1970
a month ago
by mcyc

Comments


porphyra

Reminds me of this rock paper scissors bot that has a 59% win rate against other algorithms: https://rpscontest.com/entry/614005

a month ago

bwestergard

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?

a month ago

porphyra

Apparently they downloaded a bunch of the best bots at the time and tested locally to find a seed that performs the best.

a month ago

ryan-c

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

a month ago

its-summertime

> I also had wrote some code for my former employer containing the magic string "haha jit go brrr"

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

a month ago

ryan-c

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.

a month ago

lupire

How is that related?

a month ago

fragmede

> 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.

a month ago

rdlw

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

a month ago

ryan-c

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)

a month ago

adastra22

> 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.

a month ago

ryan-c

Imagine my surprise at opening the comments and seeing a reference to some obscure art I made a dozen years ago.

a month ago

[deleted]
a month ago

Xcelerate

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.

a month ago

fragmede

Hilariously, you can plug that into ChatGPT and get a (new?) leetcode problem out.

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

a month ago

jrochkind1

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!

a month ago

eru

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'.

a month ago

nitwit005

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.

a month ago

YZF

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.

a month ago

nitwit005

I suspect you are forgetting the possibility they just didn't cover that particular proof.

a month ago

jrochkind1

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!

a month ago

YZF

Yeah. It's pretty foundational. e.g. https://en.wikipedia.org/wiki/Aleph_number I guess it's possible to teach it without going through the proof.

a month ago

[deleted]
a month ago

[deleted]
a month ago

gopher_space

How many times have you been asked to rediscover the Fibonacci sequence and then make it useful to some stupid business?

a month ago

zzigge

That seems almost like the way people curate their Magic the Gathering decks.

a month ago

RomanPushkin

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.

a month ago

deliveryboyman

This does not speak to the randomness of markets. Only the ever changing nature of them.

a month ago

eru

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.

a month ago

freediver

Reminds me of LLMs, where the weights are the 'seed' that solves standard benchmark suite.

a month ago

mcyc

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.

a month ago

b20000

so when is the last time you used this in your code you write on a day to day basis?

a month ago

hfjke

[dead]

a month ago