instruction
stringlengths
0
29.8k
⌀
The initial Mersenne-Twister (MT) was regarded as good for some years, until it was found out to be pretty bad with the more advanced TestU01 BigCrush tests and better PRNGs. [This page](http://www.pcg-random.org/other-rngs.html) lists the Mersenne-Twister features in detail: Positive Qualities -----------------...
null
$$\begin{align}1&.01111111 \\+1&.11111111111111111111111\\=11&.01111110111111111111111\end{align}$$ You obtain the same result with the calculator.
I'm implementing a q-learning agent for tic-tac-toe that requires mapping from tic-tac-toe boards to float values. Since certain game states are equivalent and should have the same value, it would be more efficient to store all games that are mirrors or $90^{\circ}$ rotations of each other, only once. Is there an algor...
Efficient algorithm/data structure that maps tic-tac-toe boards to floats
|group-theory|
null
Assign every cell a ternary digit among empty/black/white and encode the games using nine-trits numbers (base-3 digits). Base-4 can also do. Now every time you want to encode a game, generate all 8 symmetries and compute the 8 corresponding numerical codes. Finally, keep the encoding with the lowest value. That will...
Assign every cell a ternary digit among cross/dot/empty and encode the games using nine-trits numbers (base-3 digits). Base-4 can also do. Now every time you want to encode a game, generate all 8 symmetries and compute the 8 corresponding numerical codes. Finally, keep the encoding with the lowest value. That will e...
Usually LRU cache is implemented with double linked list to fast remove oldest visited, push to front, and move from any place to front; also uses map to fast find element by key.<br> In 64bit systems pointers are wide, and cache has large overhead, especially if key is long and value short. I have tested in C++ with ...
null
I recently saw [this](https://quantumcomputing.stackexchange.com/a/5217/21418) answer on a question in the Quantum Computing SE. The answer demonstrated how we can probabilistically find the answer to the Deutsch Jozsa problem on a PTM in O(1) time, with an error of 1/2^k, where k is the number of entries we check. ...
Why doesn't the Deutsch Jozsa algorithm on a classical computer show P != BPP
|complexity-theory|quantum-computing|
Let $n\in\mathbb N$. Given a set $S\subseteq\mathbb N$, let $\Delta(S) = \{a-b\mid a,b\in S\}$ be its set of differences. I'm interested in finding a small set $S_n$ such that $\{1,\ldots,n\}\subseteq\Delta(S_n)$. For example, if $n=8$ we can use $$S_8 =\{1,2,4,8,9\}. $$ > **How can we construct a small...
Constructing a small set of numbers whose differences cover $\{1,\ldots,n\}$
|algorithms|algorithm-analysis|combinatorics|number-theory|
Let $n\in\mathbb N$. Given a set $S\subset\mathbb N$, let $\Delta(S) = \{a-b\mid a,b\in S\}$ denote its set of differences. I'm interested in finding a small set $S_n$ such that $\{1,\ldots,n\}\subseteq\Delta(S_n)$. For example, if $n=8$ we can use $$S_8 =\{1,2,4,8,9\}. $$ > **How can we construct a sma...
Let $n\in\mathbb N$. Given a set $S\subset\mathbb N$, let $\Delta(S) = \{a-b\mid a,b\in S\}$ denote its set of differences. I'm interested in finding a small set $S_n$ such that $\{1,\ldots,n\}\subseteq\Delta(S_n)$. For example, if $n=8$ we can use $$S_8 =\{1,2,4,8,9\}. $$ > **How can we construct a sma...
## Interval ## Interval defined as $[l, r]$, test point $v$. Compute $|l-v|$ and $|r-v|$ to find distance from boundary. If the smallest of those distances is less than your tolerance, it's on the boundary. ## Region ## With region defined as a list of 2d points with say $x_i, y_i$, as the $x$ and $y$ coordinates ...
#### A clearer explanation Let $\beta$ be a positive integer. <!-- $\beta$ can be negative or zero. --> ($b$ will be used as a character) Let string $s=c_1c_2\cdots c_m$. Then $$H(s) = c_1\times \beta^{m-1} + c_2\times \beta^{m-2} + c_3\times \beta^{m-3} + \cdots + c_m\times \beta^0$$ where we abuse $c_i$ to al...
#### A clearer explanation Let $\beta$ be a positive integer. <!-- $\beta$ can be negative or zero. --> ($b$ will be used as a character) Let string $s=c_1c_2\cdots c_m$. Then $$H(s) = c_1\times \beta^{m-1} + c_2\times \beta^{m-2} + c_3\times \beta^{m-3} + \cdots + c_m\times \beta^0$$ where we abuse $c_i$ to al...
Copy all interval endpoints to a single array, together with a start/end flag and sort on increasing times. Sample Input-1: `[1-5, 2-3, 3-5, 3-5, 3-6]` Sorted list: `[1+, 2+, 3-, 3+, 3+, 3+, 5-, 5-, 5-, 6-]` Now by traversing the sorted list, you directly know the numbers of overlapping intervals: `[<1:0,1:1,2...
null
One example of such a set is $S_n = \{0,1,2,\dots,k\} \cup \{k,2k,3k,\dots,k^2\}$ where $k=\lceil \sqrt{n} \rceil$. It follows that $|S_n|=O(\sqrt{n})$, and $S_n$ can be constructed in $O(\sqrt{n})$ time. See also https://math.stackexchange.com/q/168079/14578.
I am enrolled in the Algorithmic Toolbox course on Coursera, and as apart of the first week that are walking us through how to implement algorithms. But I am having trouble understanding the symbol and wording that they are using. This is an example of the psuedocode: StressTest(N ,M): while true: n ← ...
What does this mean for i from 1 to n in psuedocode?
|algorithms|pseudocode|
null
null
#### A clearer explanation Let $\beta$ be a positive integer. <!-- $\beta$ can be negative or zero. --> ($b$ will be used as a character) Let string $s=c_1c_2\cdots c_m$. Then $$H(s) = c_1\times \beta^{m-1} + c_2\times \beta^{m-2} + c_3\times \beta^{m-3} + \cdots + c_m\times \beta^0$$ where we abuse $c_i$ to al...
I recently saw [this](https://quantumcomputing.stackexchange.com/a/5217/21418) answer on a question in the Quantum Computing SE. The answer demonstrated how we can probabilistically find the answer to the Deutsch Jozsa problem on a PTM in $O(1)$ time, with an error of $\frac{1}{2^k}$, where k is the number of entries w...
#### A clearer explanation Let $\beta$ be a positive integer. <!-- $\beta$ can be negative or zero. --> ($b$ will be used as a character) Let string $s=c_1c_2\cdots c_m$. Then $$H(s) = c_1\times \beta^{m-1} + c_2\times \beta^{m-2} + c_3\times \beta^{m-3} + \cdots + c_m\times \beta^0$$ where we abuse $c_i$ to al...
Why doesn't the Deutsch Jozsa algorithm on a classical computer show P != BPP?
I recently saw [this](https://quantumcomputing.stackexchange.com/a/5217/21418) answer on a question in the Quantum Computing SE. The answer demonstrated how we can probabilistically find the answer to the Deutsch Jozsa problem on a PTM in $O(1)$ time, with an error of $\frac{1}{2^k}$, where k is the number of entries w...
I recently saw [this](https://quantumcomputing.stackexchange.com/a/5217/21418) answer on a question in the Quantum Computing SE. The answer demonstrated how we can probabilistically find the answer to the Deutsch Jozsa problem on a PTM in $O(1)$ time, with an error of $\frac{1}{2^k}$, where k is the number of entries w...
Consider the problem of tiling a rectangular region with a given set of [Wang tiles][1]. It is well-known that this problem is NP-complete: every NP problem can be encoded as some form of tiling problem (see e.g. [here][2]). It is also well-known that there are particular sets of tiles that only tile the plane aperiodi...
NP-complete problems with aperiodic Wang tiles
|np-complete|tiling|
null
One problem is already explained in the answer you link to, in the part starting with "The fallacy is ... It uses an oracle.". In [the Deutsch Jozsa problem](https://en.wikipedia.org/wiki/Deutsch–Jozsa_algorithm), $f$ is provided as an oracle, so you have not proved anything about $P$ vs $BPP$, as the latter does not...
One problem is already explained in the answer you link to, in the part starting with "The fallacy is ... It uses an oracle.". In [the Deutsch Jozsa problem](https://en.wikipedia.org/wiki/Deutsch–Jozsa_algorithm), $f$ is provided as an oracle, so you have not proved anything about $P$ vs $BPP$, as the latter does not...
null
You can build a quick intuition by considering digit-only string and using the decimal value of the substring as its hash. Let's find substring "345" in string "123456789". At the first pos, we have hash 1*100+2*10+3 = 123. At second, 234. And at third, 345. In the same way, you can find for example "333" in "123...
You can build a quick intuition by considering digit-only string and using the decimal value of the substring as its hash. Let's find substring "345" in string "123456789". At the first pos, we have hash `1*100+2*10+3 = 123`. At second, 234. And at third, 345. In the same way, you can find for example "333" in "1...
I realize this is sort of a trivial ask, but I want to make sure I understand OWFs and it's usually explained with some jargon that I don't find clarifying. So, I'd just like to know whether or not my understanding of one-way functions is "essentially correct": > $f$ is a one-way function iff it can convert $n$ inpu...
Is this restatement of one-way functions accurate?
|cryptography|one-way-functions|
Let $G(V,E), |V| = n, $ be a (undirected) graph and a coloring function $f: V\rightarrow \{1,2,3...s \}$ which assigns to each vertex a color, such that in total there are $n/s$ vertices of each of the $s$ colors. Starting from a given vertex $a$, the task is to find out if there is a path in the graph, such that i...
Graph coloring with an efficient running time
|algorithms|
null
|algorithms|graphs|
The problem is NP-hard: it is as hard as Hamiltonian path, when $s=n$ and $f$ is a bijection. Therefore, you shouldn't expect any efficient algorithm that always works. You could study algorithms for the Hamiltonian path problem and try generalizing them to your situation (e.g., using a SAT solver).
It might be close, but I don't think it's 100% right. It's not clear what you mean by "find any particular specific output". Typically there's no requirement that an adversary have to try all possible inputs to $f$: it just has to be computationally infeasible to find a pre-image, on average. You could start from th...
I have an image with a list of segmentation polygons. Getting the bounding box with the polygons is easy enough. I used the bounding box to crop out the objects of interest. Now, I want to scale the polygons so that they wrap around the object. I scaled the polygons using the ratio of the original image size to the ...
Calculating the Correct Translation and Scaling Transformations for Segmentation Polygons
|computational-geometry|image-processing|
I have an image with a list of segmentation polygons. Getting the bounding box with the polygons is easy enough. I used the bounding box to crop out the objects of interest. Now, I want to scale the polygons so that they wrap around the cropped object. I scaled the polygons using the ratio of the original image size...
null
null
It really is quite simple: a promise is like an observable. It is like the Observer Pattern. (or the Publish / Subscribe Pattern). It is just a little bit difference: for promises, you can subscribe late. Meaning if the answer is ready and you "subscribe" now, you'd still get notified. Another difference is that,...
We do **not** want to use the [Levenstien Distance][1] ------------------- ### Definition of *parent* ### For any three strings $x$, $y$, and $p$, we say that $p$ is a ***parent*** of $x$ and $y$ if and only if all of the following: * $p$ is a substring of some permutation of the concatenation of $x$ an...
What algorithm will determine if two strings match eachother or not?
|substrings|edit-distance|string-matching|string-metrics|hamming-distance|
We do **not** want to use the [Levenstien Distance][1] ------------------- ### Definition of *parent* ### For any three strings $x$, $y$, and $p$, we say that $p$ is a ***parent*** of $x$ and $y$ if and only if all of the following: * $p$ is a substring of some permutation of the concatenation of $x$ an...
You can use my [master theorem solver](https://www.nayuki.io/page/master-theorem-solver-javascript) to get tight asymptotic bounds. Using your example: [![Master theorem solver][1]][1] [1]: https://i.stack.imgur.com/njYSu.png
Before I even attempt coming up with an efficient algorithm, I tried googling for similar problems but didn't get far, most queries mentioning "sets" in them led to some sort of Multiple subset sum or other subset construction problem. What I'm looking for is quite literally the opposite. The problem is very straigh...
Reconstruction of the universal set from disjoint subsets
|algorithms|sets|
null
null
It's not clear to me what your problem is (you haven't defined what you mean by "reconstruct the universal set"), but it sounds like you may be describing the [exact cover](https://en.wikipedia.org/wiki/Exact_cover) problem. This problem is NP-hard, but there are (worst-case exponential-time) algorithms for it.
null
null
null
I am struggling to understand the difference between the notions $P, NP, NP-$complete, $NP-$hard. Let's take the example of the $NP-$class. We say that these problems are solved in non-polynomial time, i.e. they have an exponential time complexity, while at the same time we say that they are verified in polynomial time...
What is the difference between solving and verifying an algorithm in the context of P, NP, NP-complete, NP-hard
|time-complexity|np-complete|
Just to share what I ended up doing: First I down sampled my point cloud from 60 million points to 60 thousand points, while keeping the shape of the object as much as possible. This was done using the opend3D function: pcd.voxel_down_sample(voxel_size=0.05) After that I used the CGAL - shape detection: [https://...
null
Just to clear things up: these classes contain *problems*, not algorithms. A problem is in $P$ if there exists a deterministic algorithm that solves it in polynomial time (there could also exist one that solves it in exponential time, that's fine). > Let's take the example of the NP−class. We say that these problems...
null
A simple example is integer factorization. Finding the factors of an integer is notoriously difficult. So difficult that it is used in cryptography applications. This is a "solving" problem. Checking that number are indeed factors of an integer is easy, by computing the remainder of the division. This is a "verif...
null
I have an image with a list of segmentation polygons. Getting the bounding box with the polygons is easy enough. I used the bounding box to crop out the objects of interest. Now, I want to scale the polygons so that they wrap around the cropped object. I scaled the polygons using the ratio of the original image size...
I have an image with a list of segmentation polygons. Getting the bounding box with the polygons is easy enough. I used the bounding box to crop out the objects of interest. Now, I want to scale the polygons so that they wrap around the cropped object. I scaled the polygons using the ratio of the original image size...
null
null
Consider an $n\times n$ sudoku puzzle $P$ that I give you as input, and you have to decide whether the puzzle $P$ is solvable. Formally, we consider the following language $\text{SUDOKU} = \{ \langle P\rangle: \text{$\langle P\rangle$ is a description of a solvable sudoku problem} \}$ Note that the language $\text{S...
Consider an $n\times n$ sudoku puzzle $P$ that I give you as input, and you have to decide whether the puzzle $P$ is solvable. Formally, we consider the following language $\text{SUDOKU} = \{ \langle P\rangle: \text{$\langle P\rangle$ is a description of a solvable sudoku problem} \}$ Note that the language $\text{S...
i am unsure if it has infinite equivalence classes or not, respectively how to interpret the textbook solution. My approach was that it has infinite because, lets say we have $x = a^5$ and $y = a^7$. If we append them with $aa$ then $x = a^7$ and thus $x \notin L$ and $y = a^9$ and thus $y \in L$. Because $9...
Does $L = \{a^n \ | \ n \geq 1, \ n \ \text{ is even or a square number}\}$ have infinite equivalence classes?
|formal-languages|regular-languages|notation|
I am unsure if it has infinite equivalence classes or not, respectively how to interpret the textbook solution. My approach was that it has infinite because, lets say we have $x = a^5$ and $y = a^7$. If we append them with $aa$ then $x = a^7$ and thus $x \notin L$ and $y = a^9$ and thus $y \in L$. Because $9...
I am unsure if it has infinite equivalence classes or not, respectively how to interpret the textbook solution. My approach was that it has infinite because, lets say we have $x = a^5$ and $y = a^7$. If we append them with $aa$ then $x = a^7$ and thus $x \notin L$ and $y = a^9$ and thus $y \in L$. Because $9...
null
null
Given an array of N integers, there may be a need to perform q queries. A query could be like determining the number of values that are less than an integer k. Which data structure could be used to minimize Time Complexity? **My Thoughts:** One easy way could be to keep the numbers sorted. And then, for each q...
Data structure to determine number of values less than an integer