It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What's the easiest way to get two nibbles (as Integers) from a byte in Ruby?
If the "byte" is a number between 0 and 255:
n1, n2 = (byte & 0xf0) >> 4, byte & 0x0f
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have N points. Each point has X and Y coordinates.
I need to find X and Y of center of mass this points. Can you give me an algorithm to accomplish this task?
Is there something wrong with just taking the weighted average by mass?
for each point n
{
totalmass += n.mass
totalx += n.x*n.mass
totaly += n.y*n.mass
}
center = (totalx/totalmass,totaly/totalmass)
add additional dimensions as appropriate.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Please help solve this:
Telephone numbers are often given out as a word representation, so that they are easy to remember. For example if my number is 4357, the text given is HELP. There could be many other possibilities with the same digits, most of which do not make sense.
Write a space-and-time-optimal function that can, given a phone number, print the possible words that can be formed from it.
Based on the detailed explanation in the comment this should be a simple permutation combination problem:
Each digit will have a number of characters associated to it (example 4 could mean either of G,H or I) and then for a combination of digits the permutation can be computed.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
There is a 3D grid with cells for which we define its value (0 or 1) as F(i,j,k)=F(i-1,j,k) XOR F(i,j-1,k) XOR F(i,j,k-1), base cases are F(0,0,0)=1 and F(x,y,z)=0 for x < 0 or y < 0 or z < 0 (if at least one parameter is negative).
We want to count amount of cells with F()=1 in the cube with corners (0,0,0) and (N, M, K). Dimensions are about 2^30.
I'm looking for the fast approach on this problem.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
In an array, there is exactly one element which repeats odd number of times and rest all other elements repeat even number of the times. Find the element optimally
xor all the elements together.
Example:
In [3]: reduce( lambda x,y : x^y, [1, 2, 2, 1, 4, 5, 5] )
Out[3]: 4
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Problem statement:
You are given a set of k strings, each length n. You have to output the group of anagrams together. Anagrams are like e.g atm - mat , like-kile.
Just sort the word's letters to obtain a signature that's anagram-specific. E.g., in Python,
sig = ''.join(sorted(word))
and make a dict with sig as the key and the value being a list of words with that signature (defaultdict(list) works well for this). Of course, you can do it in any language with sorting abilities, and associative arrays whose values can be lists or vectors;-).