New answers tagged

1

Why not read Frye's article? Here is a digest. You do need modular arithmetic to sieve candidates. Mod 5 works like charm (200 times reduction of the search space). You need to split it in A^4+B^4 and D^4-C^4. The program itself is written in Lisp. The implementation is reasonably straightforward, while the underlying math is neat. First He sieves out ...


0

You are looking to solve a problem that originates from a mismatch between the type of information you want to work with (ordered sequence) and the data you have (unordered set). A good strategy to fix this is to make sure that information and data match, because then the program will be straightforward. So I'd recommend the following approach: Build an ...


0

The easiest way is brute force. Generate all the ways to order the numbers and apply the operators, then see if any matches the target value. This will scale very badly, but can be improved with heuristics. Using your example, we can notice that we only need to try division when it will come out to an integer (assuming you don't mean / as truncating integer ...


2

Modular arithmetic is the key. First of all, take the total and add all its bytes together. If any carries occur, add those into the total as well (for instance, F0+F6=E7). Continue until you have a single-byte value. The process works just as well if you start by adding 32-bit words to 32-bit words until you have a 32-bit result and then the 16-bit "top ...


2

Create one data structure that creates all sums of two fourth powers in ascending order, and another one that creates all positive differences of two fourth powers in ascending order. Then compare the numbers from both lists in ascending order. That way you have only O (n^2) numbers to check instead of O (n^3). Basically, search for a^4 + b^4 = c^4 - d^4. ...


0

wigy posted a link to some stuff that is highly relevant but I think there are a few simple things that can help here. I'll offer some suggestions that are probably not optimal but might help you move forward. The first thing I would suggest is to avoid iterating over every other user for one user. I would instead iterate through the songs that user has ...


3

I am not sure, how exactly you compute 4th power root, but this operation is very expensive. Likewise computing 4th power is costly. Using a database to precompute 4th powers up to a million might save you a lot of resources. Likewise, you can start with a perfect power and try subtraction rather than addition. This way you will skip 100^4+1^4+2^4 cases that ...


2

Sorry I didn't read your question correctly at first (and have deleted my comment) //How about this from G = {g[0],g[1],g[2],....} create the set G[0] = { {g[0]}, {g[1]}, {g[2]},...} for each w_i in W find the element c in G[i] such that c contains a point p where p originally came from G, and p is closest to w_i //we want to group w_i along ...


-1

using System; using System.Collections.Generic; using System.Text; namespace target { enum Op { Plus, Minus, Times, Div }; class OpSymbol { public Op _op; public string _symbol; }; class IntExp { public static OpSymbol[] _op_symbols = { new OpSymbol { _op = Op.Plus, _symbol = "+" }, new OpSymbol { _op = Op.Minus, _symbol = "-" }...


2

This is a very broad topic. Unfortunately there's no general answer, due to the complex matter of patentability. And in view of the existing practice of patent trolling, there is always be some legal risk to be sued in countries in which software patents are accepted. As a first intro, you may be interested in this WIPO article, and especially TIP3, about ...


0

To answer your question about how to know which route to choose, you need to make the choice that will maximize your accumulated score. So in your example, if you're trying to decide between a route that gives you 5 and one that gives you 3, you will choose the greater one (5). Your reasoning on using a table to utilize dynamic programming for this problem ...


1

I don't have a practical comparison between Pearson hashing and the other common suggestions, but I can highlight some assumptions you're making that aren't necessarily true and which might explain why it isn't as popular as you seem to expect: You state that having good distribution of small keys throughout the entire range is just as important as good ...


1

Since most hash algorithms (at least cryptographic ones like the SHA family) are designed to prevent what you're trying to do, you won't have an easy time of it. Some older hash functions like MD5 do have some vulnerabilities, though.


0

I think Doc Brown hit upon the real problem: it is a compression problem. As such, first streaming the numbers to a binary representation (compressed bits, a byte array) and then encoding using the letters is probably the best solution. When you stream to a binary representation, include the length of any variable sized collection as the header before the ...


2

A dictionary where the key is the word encountered, and the value is a count of the number of times that word is encountered. I think your question has some hidden problem you did not explain. This is trivial.


2

From the comments, it appears that you are dealing with 1 000 points. The usual way to compute a distance between two points, p1 and p2, is: sqrt(pow(p1.x - p2.x, 2), pow(p1.y - p2.y, 2)) I attempted to measure the time it takes to do the operation in C# on a 2.10 GHz CPU (no parallelization, so the number of cores doesn't matter), and failed. With 10 ...


0

You are going to have to consider each and every supplier, as each one has a different radius. There is no way you can stop checking suppliers once one fails the distance test as another further one might deliver a larger radius! What you can do is reduce the calculations by considering all those suppliers distance horizontally, and then if they are closer ...


2

This is called sharding in MongoDB and partitioning in SQL Server. If the website actually uses “huge amounts of data”, sharding/partitioning is already implemented. You may probably want to rethink what data you actually need to retrieve, how is it used and how do you store it. If you do auto-completion on product names, you probably don't need to retrieve ...


1

If the equation cannot be solved analytically, you need to use numerical algorithm. To make it simple rewrite the equation into form of X + 2 - Y = 0. Then, it becomes a problem of finding a root of equation using numerical method.


1

If your scene is static (i.e., your triangles don't move, so you can amortize building your acceleration datastructure across all your lines), then I believe that a highly optimized kd-tree is still state of the art for this purpose. Because they have finite extent, your triangles may overlap more than one branch of the kd-tree tree; however, that will be ...


0

I would use a breadth-first approach. Split the large image into tiles and have each worker own one tile, and also know what its neighbors are. Fill the first tile as normal. If any locations touch the edge of the tile and there is a neighbor in that direction, send a message to the neighbor with the location and color information so it can decide whether or ...


4

Fortunately, there is a much simpler approach than your multi-threading alternative: implement your backtracking using queues or stacks, instead of recursivity. In this case, when your top state is a solution, you can return it. And you can resume backtracking to find the next solution by processing the next state in the queue/on the stack. This ...


1

You could be using a semi-co-routine, or generator. They do not exist in all languages and do not always directly allow recursion. But the capability of doing so and availability of semicoroutines don't depend on availability of threads (granted, they're much easier to implement with threads or fibers, so they're probably more readily available on some ...


0

Here is one of the efficient algorithm for counting number of divisors and also summing them up for giving the correct output. import java.math.BigInteger; import java.util.Scanner; class ProductDivisors { public static BigInteger modulo=new BigInteger("1000000007"); public static BigInteger solve=new BigInteger("1"); public static BigInteger two=new ...


-1

I did mine using greedy. Basically for each string in the set, I compare it with the rest of the strings in the set, and find the most duplicated one, and merge the two. And keeps doing it until only one string left in the set. You can look at there for some other solutions people made. https://www.reddit.com/r/dailyprogrammer/comments/46km7n/...


0

Lempel-Ziv style compression does the kind of thing you're looking for. For your application, it sounds like you want a fixed "string dictionary" (LZ's internal representation of your token definitions), rather than the dynamic one used by standard streaming compression programs like gzip or compress. The general Lempel-Ziv scheme is readily adaptable to ...


0

If you start at the top of the triangle there's only 2 choices to continue the path - left or right. If you chose left, then there's only 2 choices to continue the path - left or right. If you chose right, then there's only.... Let's encode the "left or right" decision at each level as 1 bit, where 0 = left and 1 = right. If there are 5 levels you can ...


1

Matrix decomposition is definitely the way to go here. Which decomposition you use will be determined by the structure of the systems you are are trying to solve: solving using Cholesky decomposition requires a square, symmetric, positive definite, matrix. You can solve a general square matrix using LU or QR. LU is typically used because it usually takes ...


1

Rough Modeling The conventional aspects of house design and construction suggest modeling with a domain specific language that captures the business logic of dwelling and dwelling life cycles might be easier than using a general purpose programming language. Rough Mathematics Though there are bounds on house configuration from convention, mathematically, ...


0

Simple counter example. Let's place all points on the X-axis. The points are at -1, 0.1, 1, and 2. The shortest link in this graph is from 0.1 to 1. The greedy algorithm takes this path, then greedily continues to 1, then 2, then it is forced to take the longest possible link to reach -1. The total length is 4.9. The shortest route is either to start at one ...


-1

We will ignore the last group here. Order within a group doesn't matter, so let's stick with alphabetical order. If you nest your loops the right way they will only generate letters that are in alphabetical order. The order of the groups doesn't matter. So let's stick with groups that are in alphabetical order relative to each other. Again, if you nest ...


3

No, there is no hope. The fastest thing you can do is replace characters in an array instead of generating a new string object at each iteration. But whatever processing you plan to do with each permutation will presumably take considerably longer than it took to generate the permutation in the first place.


0

Instead of asking "why does the last approach work", you should ask "does the last approach work". It doesn't. start is increased by 1 exactly once in each iteration of the loop, and curr_sum will be equal to 0 after start is increased. This will never find a solution unless sum == 0. I strongly suspect that there should be some "while" statement before the ...



Top 50 recent answers are included