I know how to simulate a 2d array in a linear array using [x + y * width] as a linear index.
I can extend this to 3d arrays: [x + y * width + z * width * height].
Is there a general formula for N-dimensional array?
I'm looking for a language-agnostic answer.
...
Is there a valid math term? I could just name this guy "sumXY", but that is (a) lame, and (b) not scalable, since going up a dimension would require a rename.
While typing I thought of "componentSum", but I'd love to know if there's a real name for it.
...
Can someone please explain this to me?
...
My department is working on a project that requires us to heavily communicate with another team, whose software ours has to interact with.
Today this resulted in a 4 1/2 hour conference call where the whole team had to attend, with very few results and no progress in the actual coding at all. To me, it was a complete waste of time, exce...
Sorry if I am asking same question again but want to verify!
I have two processes P1 and P2.
P1 is a writer (Producer).
P2 is a reader (Consumer).
There is some shared memory or a file that P1 writes to and as soon as P1 writes, P2 should be notified for reading.
Now as per my understanding pseudocode for P1 should be
Open shared ...
This is one of an interview question which I had recently. I would like to know others perception of approach for this problem.
Question:
You are given a structure which holds an employee details with two elements as int Deptartment and string Name.
struct Employee
{
string Name;
int Dept;
}
You are given details of N Emplo...
There is a function that calls itself recursively infinitely.
This function has some arguments too.
For every function call the arguments and return address are pushed on the stack .
For each process there is fixed size of stack space that cannot grow dynamically like heap.
And I guess each thread also has its own stack.
Now if a fun...
Problem:
I need to design a networking application that can handle network failures and switch to another network in case of failure.
Suppose I am using three ethernet connections and one wireless also . At a particular moment only one connection is being used.
How should I design my system so that it can switch to another network in ...
This is one of an interview question. You need to design a stack which holds an integer value such that getMinimum() function should return the minimum element in the stack.
For example: consider the below example
case #1
5 --> TOP
1
4
6
2
When getMinimum() is called it should return 1, which is the minimum element
in the stack.
...
I've written a program to perform run length encoding.
In typical scenario if the text is
AAAAAABBCDEEEEGGHJ
run length encoding will make it
A6B2C1D1E4G2H1J1
but it was adding extra 1 for each non repeating character. Since i'm compressing BMP files with it, i went with an idea of placing a marker "$" to signify the occurance of a...
The only algorithm that I know for this problem is the Newton's method (make a guess, then improve it until it's good enough).
Any other ideas (use any language you prefer)?
PS: Of course I don't have any use case for this, I'm just researching it for academic reasons.
...
I want to shut down the remote computer (ex. a computer connected in LAN.) I have tried a lot but I could not find the solution. Does anyone have an idea on how to shut down the remote computer? Any language would work.
...
At the one end of my web application I have a database table storing a load of pieces of text.
In the middle I have an API that separates my application tiers.
At the other end I have a user interface consisting of many TextBoxes (or input type=text form elements, if you prefer).
I need the maxlength properties of the TextBoxes to be ...
Following on the heels of What is your preferred site for code snippets, I'm looking for a website to post a short blurb of formatted code.
I don't want to create a login. I'm looking for a simple: paste, use and forget. I know it exists, I've used it before, but my google skills are failing me!
...
When converting from RGB to grayscale, it is said that specific weights to channels R, G, and B ought to be applied. These weights are: 0.2989, 0.5870, 0.1140.
It is said that the reason for this is different human perception/sensibility towards these three colors. Sometimes it is also said these are the values used to compute NTSC sign...
I read spin lock code from here, especially this part
inline void Enter(void)
{
int prev_s;
do
{
prev_s = TestAndSet(&m_s, 0);
if (m_s == 0 && prev_s == 1)
{
break;
}
// reluinquish current timeslice (can only
// be used when OS available and
// we do NOT wa...
In order to allocate enough space for an array element for each weekday of a year, I'm trying to work out the maximum number of rows I would need. That lead me onto the question of how I would work it out.
Would you have to calculate the number of days in every year for the next n years and go with that? Or is there (as I suspect) a mo...
Are there any tools or IDE features to allow viewing of different parts of the same file side-by-side.
I've often thought this would be useful for analysing and refactoring duplicated code within a file.
...
I recently read that a method involving hashing could be a good way to find the mode of an array of floating point numbers. I don't know much about hashing or its applications and the text didn't explain further.
Does anyone know what this method would involve?
...
I know I am not the only one who does not like progress bars or time estimates which give unrealistic estimates in software. Best examples are installers which jump from 0% to 90% in 10 seconds and then take an hour to complete the final 10%.
Most of the time programmers just estimate the steps to complete a task and then display curren...