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.
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 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
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 came across this question and couldn't figure out how to approach it. Can someone please help me out? The question is-
Add numbers in base n (not any of the popular ones like 10, 16, 8 or 2 - I hear that Charles Simonyi, the inventor of Hungarian Notation, favors -2 when asking this question).
I just need the idea.
You didn't specify a language, but you could just convert the base n number into a standard integer and add it.
Suppose base N number = '...d2d1d0' where di = the i'th digit.
Number = ... d2 * N^2 + d1 * N^1 + d0 * N^0
Then just add the numbers as usual.
Idea: it looks like hashing, but in hash function you can't use negative numbers.
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.
Can anyone please let me the efficient algorithm to count the number of 9s present between 1000 and 2000.
Since it's a fixed number you could precalculate it and hard code it.
There should be 300 nines in that interval.
There is 100*1 nines as the first digit (1009, 1019, ...)
There is 10*10 nines as second digit (1090, 1091, ..., 1190, 1191, ...)
There is 1*100 nines as third digit (1900, 1901, ...)
I can add that 1999 counts as 3 nines for me.
A simple way to do this in JavaScript (since you didn't mention a language) would be
var x = 0,
i = 1000;
for (; i < 2000; i++) if (/9/.test(i.toString()))
x++;
When the loop finishes, x would be the amount of numbers between 1000 and 2000 with the number 9 in them.