Hello,
I'm trying to write a function that repeatedly matches regexp patterns against an input string. The function should take pattern 1 match it against the input string and split it into parts of matching and non-matching segments. Pattern 2 would subsequently be used on those non-matching segments, until all input patterns are used...
I am trying to create a solvability function for a game algorithm. Basically a function that returns true or false for a given game it if is solvable or not.
The game is Buttonia.com (which does not implement the algorithm as yet), a type of lights-out game. Basically You have a grid of buttons, each of which, when pressed, will change ...
Ive got a bunch of rectangular objects which I need to pack into the smallest space possible (the dimensions of this space should be powers of two).
I'm aware of various packing algorithms that will pack the items as well as possible into a given space, however in this case I need the algorithm to work out how large that space should be...
Trivial using a for loop or each_with_index, just wondering if there was a better way of doing it using Ruby syntax.
I need to create a new array that is the derivative of the source array, eg:
for(int i = 1; i < oldArray.length; i++)
{
newArray[i] = oldArray[i] - oldArray[i-1]
}
...
I need to generate a CRC table for the standard CRC-5 algorithm, (or at least need some way to validate that the table I have is indeed correct). I was under the impression that CRC-5 would simply utilize 5 bits to calculate the CRC value, but in my table below I notice some first bytes with values greater than 7.
Is this correct and is...
I'm programming a site in PHP/MySQL that gets search results for products via API from an external site. This site also will have it's own products and the owners of the site want the search results to be inter-connected.
If someone searches for VIDEO, ordered by date then the results should be all in order regardless of the source it...
I have 4 points that form some quadrilateral. The lines can't cross or anything like that, it should be a square, rectangle, rhombus, parallelogram, etc.
The lines that connect them break the field into 9 regions. With a square, it would look like a tic-tac-toe board (#), but with other shapes the lines will be at angles.
A point falls...
This is literally about comparing cakes. My friend is having a cupcake party with the goal of determining the best cupcakery in Manhattan. Actually, it's much more ambitious than that. Read on.
There are 27 bakeries, and 19 people attending (with maybe one or two no-shows). There will be 4 cupcakes from each bakery, if possible incl...
I have a requirement that goes as follows (trust me, I'm way too old for homework grin)
I have a bunch of tasks that run with various frequencies. They also have a start "seed" date/time . The start seed is sometime in the past, could be one minute ago, could be 5 years ago.
I need to calculate the next run time for the task, using th...
What is a good way to implement Gaussian elimination when the operators are custom operators, rather then standard arithmetic ones?
Here are the operators:
Addition:
0 + 0 = 0
0 + 1 = 1
1 + 1 = 0
Subtraction:
0 - 0 = 0
0 - 1 = 1
1 - 1 = 0
Multiplication:
0 * 0 = 0
0 * 1 = 0
1 * 1 = 1
Division:
0 / 0 = illegal
0 / 1 = 0
1 / 1 ...
Given a large sparse matrix (say 10k+ by 1M+) I need to find a subset, not necessarily continuous, of the rows and columns that form a dense matrix (all non-zero elements). I want this sub matrix to be as large as possible (not the largest sum, but the largest number of elements) within some aspect ratio constraints.
Are there any known...
I'd like to know if anybody can provide a step-by-step how to on how to use mediation analysis using Keele, Tingley, Yamamoto and Imai's mediation package. I think there are two approaches to this - the classic Baron and Kenny (1986) and the new one by Preacher, Rucker and Hayes (2007) - I'd like to know how to do both approaches in R
...
Purpose
I'm writing a small library for which portability is the biggest concern. It has been designed to assume only a mostly-compliant C90 (ISO/IEC 9899:1990) environment... nothing more. The set of functions provided by the library all operate (read/write) on an internal data structure. I've considered some other design alternatives,...
How can I find the preorder listing of a tree if only the postorder listing is given and vice versa. Also, in the tree, every non-leaf node has two children (i.e. Each node has either two or zero children.)
EDIT: Another given assumption is that the label of each node is unique and has a field that will identify it as an internal node o...
Lots of editors and IDEs have code completion. Some of them are very "intelligent" others are not really. I am interested in the more intelligent type. For example I have seen IDEs that only offer a function if it is a) available in the current scope b) it's return value is valid. (For example after "5 + foo[tab]" it only offers function...
Hi, I like to watch programming screencasts and listen to podcasts on those topics.
Lately I got into doing online topcoder algorithm competitions and am studying algorithms day and night.
Where online can I find video/audio materials related to algorithms?
I know others here have asked about general programming videos and podcasts, b...
I am working on a programming exercise that has interested me for some time. The goal of this exercise is to generate a softball schedule for a seasons programatically. What I am looking for is general advice rather than a specific anwser as I am trying to learn something in the process.
The part of the program I am really struggling wi...
A binary tree can be encoded using two functions l and r such that for a node n, l(n) give the left child of n , r(n) give the right child of n.
A branch of a tree is a path from the root to a leaf, the length of a branch to a particular leaf is the number of arcs on the path from the root to that leaf.
Let MinBranch(l,r,x) be a simple...
I have a situation where I need to allocate people to several events. If we just had a price as a factor, it would be fine, but there is a number of factors that come in.
First, some background. This is for a non-profit organization that promotes story hours for children that are hospitalized for any reason, so they depend on voluntary ...
I have a code that looks something like this:
struct First
{
int f1;
int f2;
};
struct Second
{
First s1;
int s2;
};
std::vector < Second > secondVec;
Second sec;
sec.s1 = First();
secondVec.push_back(sec);
secondVec.push_back(sec);
std::vector < First > firstVec;
firstVec.reserve(secondVec.size());
for (std::vect...