Tag Info

New answers tagged

6

BigInteger and BigDecimal are immutable objects. Once instantiated, if you want to do something with it, you create a new object. This isn't a problem per say, and actually avoids many other problems (especially when threading), and numbers tend to be things that are constants - you don't change them. It is very common for code that is working with ...


0

You're going to find a variety of links between Java and X industry. Recall that a lot of sold-state and integrated circuits run Java in a "baked-in" approach. So most of the semiconductor industry jobs are having you write Java for chipsets, circuits, etc. It's still Java, just different frameworks and whatnot that you will have to adapt to; you'll be fine. ...


-1

As others pointed out here and on http://stackoverflow.com/questions/4948780/magic-numbers-in-boosthash-combine, the number is indeed constructed from the golden ratio. But there is another important reason why numbers such as pi, phi or e are used in cryptographic functions. Of course, in principle, any "reasonably random" bit sequence could be used as a ...


1

Whatever you do, document it. If users do not like the default behaviour you provide, they can then adapt your function to their needs. Here are a couple of possibilities, sorted from best to least preferred (in my opinion). There is no sensible value in these cases, so we need to return the absence of a value. This might be a double* or double? with a ...


6

OO is not about syntax. Just because you use object.function() vs function(object), that doesn't mean you are now "doing OO." OO is about sending messages to objects to inform them about events, without knowing or caring how they will react to those events. Vector math is not OO in nature and it would be a mistake to try to force it into an OO context. In ...


2

You can solve this with a standard breadth-first search, with the addition of also storing the path taken to a node whenever you enqueue it in the to search queue. BFS algorithms avoid loops by keeping a visited or discovered set. Because they use a queue instead of a stack, they are not normally implemented using recursion, unless the implementation uses ...


0

I think you should probably use a union-find algorithm to find all connected groups of n-letter words that can transform into each other. Preprocess you dictionary with it, and before you start searching see if the two end words are in the same connected group. The preprocessing will only take time proportional to the number of valid word-to-word ...


5

It seems that what you're really trying to do is figure out if two nodes in a graph are in the same connected component. Specifically the graph is an undirected one in which the words of your dictionary are nodes, and two nodes are connected to each other by a vertex when they differ by exactly one letter, and are the same length. The root of the problem is ...


0

I assume you are using recursion for this. Every transformation is a unit of work to be done, hopefully it is handled in one method, or group of methods. When you jump to next word, keep track of all the words that you have already been at during this specific path and check the available options against the list of those words to exclude the ones that you ...


1

To solve the question you pose, you must understand complete search, and for that you have to understand recursive algorithms. This simply means that you must reduce e.g. the problem of reaching "tree" from "full" to the problem of reaching "free" from "full", and handle the intermediate data correctly.


1

The number comes from the hexadecimal representation of the golden ratio. Just like 1/4 is 0.25 (25/100) in decimal is 0.4 (4/16) in hex, the fractional portion of the golden ratio has a different representation in hex than in decimal. You are not dividing 0x9e3779b9 by 10^8, but 16^8 (or 2/32), and 0x9e3779b9/0x100000000 = 2654435769/4294967296 ≈ ...


2

This is a simple Python implementation: from random import random def select(container, weights): total_weight = float(sum(weights)) rel_weight = [w / total_weight for w in weights] # Probability for each element probs = [sum(rel_weight[:i + 1]) for i in range(len(rel_weight))] for (i, element) in enumerate(container): if ...



Top 50 recent answers are included