Finding a random seed that solves a LeetCode problem (2023)
Marco Cognetta explores generating a unique bitstring not in a given list using a random seed and a deterministic hash function, successfully identifying a valid seed after 42 attempts.
Read original articleMarco Cognetta discusses his approach to solving a LeetCode problem by finding a random seed that generates a unique bitstring not present in a given list of unique bitstrings. The challenge involves generating a new bitstring of the same length as the input strings, which can be approached through various methods, including Cantor's diagonalization argument. Cognetta's method involves using a random seed influenced by the input to ensure that the generated bitstring is not already in the list. He explains the probability of randomly generating a valid answer, noting that while the odds seem low, they improve with smaller input sizes.
He details his implementation, which includes creating a deterministic hash function to generate the seed based on the input bitstrings. This function computes a value from the characters and their positions in the array. After testing various seeds, he successfully identified a seed that passed all test cases after 42 attempts. He reflects on potential improvements, such as optimizing the hash function and addressing input duplicates, which could have expedited the process. Overall, Cognetta's exploration highlights the intersection of randomness and algorithmic problem-solving in coding challenges.
Related
The Magic of Participatory Randomness
Randomness is vital in cryptography, gaming, and civic processes. Techniques like "Finger Dice" enable fair outcomes through participatory randomness, ensuring transparency and trust in provably fair games.
Exploring Randomness in JavaScript
This article compares Math.random() and Crypto.getRandomValues() in JavaScript for generating random values. Despite Crypto being more secure, Math.random() suffices for creating color palettes due to speed and perceived randomness.
How random are TOTP codes?
The blog post examines TOTP code randomness using HMAC with SHA-1. It analyzes digit frequency in generated codes, showing diminishing bias over generations. Readers discuss and suggest additional analysis methods.
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.
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.
Related
The Magic of Participatory Randomness
Randomness is vital in cryptography, gaming, and civic processes. Techniques like "Finger Dice" enable fair outcomes through participatory randomness, ensuring transparency and trust in provably fair games.
Exploring Randomness in JavaScript
This article compares Math.random() and Crypto.getRandomValues() in JavaScript for generating random values. Despite Crypto being more secure, Math.random() suffices for creating color palettes due to speed and perceived randomness.
How random are TOTP codes?
The blog post examines TOTP code randomness using HMAC with SHA-1. It analyzes digit frequency in generated codes, showing diminishing bias over generations. Readers discuss and suggest additional analysis methods.