Given an array A which holds a permutation of 1,2,...,n. A sub-block A[i..j] of an array A
is called a valid block if all the numbers appearing in A[i..j] are consecutive numbers (may not be in order.
Given an array A= [ 7 3 4 1 2 6 5 8]
the valid blocks are [3 4], [1,2], [6,5], [3 4 1 2], [3 4 1 2 6 5], [7 3 4 1 2 6 5], [7 3 4 1 2 6 5 ...
Given a datetime column in mysql 5, I want to find out the day of the week ?
But the function DAYOFWEEK returns 1 for Sunday.
I want 1 to denote monday, 2 tuesday etc.. and 7 to denote Sunday.
Is there a one-liner (that can be embedded in a larger SQL statement) that implements this function ?
f(x) => y
such that:
f(1) = 7
f(...
Hello,
I'm developing a Texas Hold 'em hand-range equity evaluator, which evaluates hand-distributions with Monte Carlo -simulation. I've faced two annoying problems which behaviors I cannot give any reason.
Problem #1:
In a nut shell, the evaluator works by first picking up hands from player's hand-distributions. Say, that we have th...
Is there a standard for this? Algorithm name?
Say:
I have 10 polygons of different sizes.
I have an area of specific size.
I want to know how to fill the most polygons in that area, and how they are fitted.
Note:
Polygons may be rotated depending on the restriction set.
...
I'm trying to make a vista minesweeper clone. Right now my uncover algorithm is the cascade algorithm. It kind of looks like a square that gets bigger and bigger. I noticed in vista mnesweeper, when its gameover, it iterates through the game in a circular manner to uncover the mines. Does anyone know what this algorithm is called? Thank...
Hello everyone there...
I have a problem, suppose I have a given string: "best", the target string is suppose: "beast". Then I have to determine the number of operations to convert the given string to the target string, however the operations allowed are:
1. add a character to string.
2. delete a character.
3. swap two char positions. (...
Hi i am trying to calculate the complexity of the following algorithm
private static List<int> GetIndexes(string strippedText, string searchText)
{
List<int> count = new List<int>();
int index = 0;
while (strippedText.Length >= index && index != -1)
{
index = strippedText.IndexOf(searchTex...
If there is more than one constraint (for example, both a volume limit and a weight limit, where the volume and weight of each item are not related), we get the multiply-constrained knapsack problem, multi-dimensional knapsack problem, or m-dimensional knapsack problem.
How do I code this in the most optimized fashion? Well, one can dev...
Hi guyz,
I need some help with a algorithm I'm working with for my college course. The idea is use an artificial neural network to read a electrocardiogram and try to recognize some disturbs in the waves, that's ok, I've the neural network and I can test it, no problem, but I'd like to give the function to the user to open a eletrocardi...
I am making a simple AI and I am really new to this realm. What I need is an algorithm to make some sort of decisions based on some parameters; but with a little bit of randomness. What I have been doing so far is to generate a random number and based on the different values I get; take different execution paths. I somehow think there's ...
The dot product of two n-dimensional vectors u=[u1,u2,...un] and v=[v1,v2,...,vn] is is given by u1*v1 + u2*v2 + ... + un*vn.
A question posted yesterday encouraged me to find the fastest way to compute dot products in Python using only the standard library, no third-party modules or C/Fortran/C++ calls.
I timed four different approach...
As part of a program I'm writing, I need to solve a cubic equation exactly (rather than using a numerical root finder):
a*x**3 + b*x**2 + c*x + d = 0.
I'm trying to use the equations from here. However, consider the following code (this is Python but it's pretty generic code):
a = 1.0
b = 0.0
c = 0.2 - 1.0
d = -0.7 * 0.2
q = (3*a...
I am trying to do a preorder traverse
...
Ok, I'm not sure if the title is that effective but its the best I could come up with.
Basically here is the scenario.
I have 11 categories. In each category, I have items, but one category might have 1 item, 1 might have 20.
Now i want to separate the 11 categories into 5 stacks or columns.
I want each of the stacks to contain an eq...
I have two sets A and B.
A
--
1
2
6
B
--
1
2
3
4
When I compare set A with B, I need to get value 6 as output and value 4 as output when set B is compared against A.
I am wondering what would be the best algorithm to do this? I have wrote one but it has got a quadratic complexity. It basically iterate one set and inside the loop it...
I originally had this code which I mistakenly thought would do what I wanted it to:
string firstArg = args[0];
string[] otherArgs = args.Except(new string[] { args[0] }).ToArray();
However, it seems that the .Except method removes duplicates. So if I was to pass through the arguments a b c c, the result of otherArgs would be b c not ...
Ok, so I've been doing some experiments with hash tables and different collision resolution problems. I'm trying to figure out which is more efficient for doing finds, a hash table that uses separate chaining or quadratic probing for collision resolution. My results suggest that separate chaining is faster than quadratic probing even for...
Thanks to everyone replying with ideas and alternate solutions. More efficient ways of solving problems are always welcome, as well as reminders to question my assumptions. That said, I'd like you to ignore for a moment what problem I'm trying to solve with the algorithm, and just help me analyze the big-Oh complexity of my algorithm as...
I need an Algorithm which is used to find the N-element randomly-ordered integer
array is either already sorted or not.
...
Not strictly a question, more of a puzzle...
Over the years, I've been involved in a few technical interviews of new employees. Other than asking the standard "do you know X technology" questions, I've also tried to get a feel for how they approach problems. Typically, I'd send them the question by email the day before the interview, an...