algorithm

Calculate percent at runtime

I have this problem where I have to "audit" a percent of my transtactions. If percent is 100 I have to audit them all, if is 0 I have to skip them all and if 50% I have to review the half etc. The problem ( or the opportunity ) is that I have to perform the check at runtime. What I tried was: audit = 100/percent So if percent is...

Algorithm to find matching pairs in a list

I will phrase the problem in the precise form that I want below: Given: Two floating point lists N and D of the same length k (k is multiple of 2). It is known that for all i=0,...,k-1, there exists j != i such that D[j]*D[i] == N[i]*N[j]. (I'm using zero-based indexing) Return: A (length k/2) list of pairs (i,j) such that ...

Water Jug problem in Die Hard 3 into a graph

Hi, im not too sure how to implement this... I need to create a weighted directed graph based on the water jug problem from the movie Die Hard 3 (http://www.wikihow.com/Solve-the-Water-Jug-Riddle-from-Die-Hard-3). I need to create nodes for all the possible moves (fill, empty, pour). After i need to find the shortest path to the soluti...

How to implement tag system

Hi, i was wondering what the best way is to implement a tag system, like the one used in SO. I was thinking of this but i can't come up with a good scalable solution. The things i was thinking was is the basic 3 table solution. Having the tags table, the 'articles' tables, and a tag_to_articles table. Is this still the best solution to...

Position boxes like in Exposé

Hi! Does anyone know a way to locate rectangles to best fit a certain area? The rectangles can be scaled up to a certain limit, but they should keep their proportions. I basically want to rebuild Mac OS' Exposé: Picture Thanks, eWolf ...

Algorithm to implement kinetic scrolling

What are the good algorithms to apply to kinetic scrolling implementation? The feature would be tested on custom UI list. While I am targeting mobile devices (those that do not have this feature built-in), any algorithm or code example from different programming field may also suit. Thank you. ...

Finding neighbour blocks on a grid

I have a grid like this: 1234567 1 ACBDBAB 2 ABDBABC 3 ABADBAB 4 BABDAAB 5 BABCDBA 6 BDBABCB 7 ABBCBAB Given a certain coordinate, for example (3:4), I'd like to find all the other blocks with the same letter that have at least one common side with the original block and one of those block (recursively). On my example, I'd like the ...

Frequency based sorting

You are given an array of integers and you have sort those integers based on the frequency of their occurrence. Design an algorithm and analyze its time complexity. In case of ties the smaller number should appear first in the sorted list. Sample Input: 3,4,3,2,3,5,4,2,2,1,2 Sample Output: 1 5 4 3 2 ...

Software and Bio-Mimicry

I'm wondering if anyone knows of any software techniques taking advantage of biology? For example in the robotics world there are tons but what about software? ...

How to get the second highest number in an array in Visual C#?

I have an array of ints. I want to get the second highest number in that array. Is there an easy way to do this? ...

How to implement this oscillation function

What would be a fast way to implent this osscilation function. A signature would look like this: public static double Calculate(UInt64 currentCounter, uint duration, uint inDuration, uint outDuration) And the result should be a double that as currentCounter advances, ossciates between 0 and 1. The osscialtion speed is defines by the d...

Is it possible to have a rotationally invariant identifier of a boolean matrix?

Say I have a matrix of ones and zeros, and I would like a 'identifier' for this matrix that takes the same value regardless of whether the matrix is rotated by 90, 180, or 270 degrees, i.e. a 4-to-1 mapping. Ideally, this identifier should be 1/4 the size of the matrix. Is it possible to write a function that does this mapping? Backgrou...

How do I find the derivative of sin(x) using recursion?

How do I find the derivative of sin(x) where x could be any value e.g. 1,2,3 using recursion? ...

Name of a particular algorithm

Hi, I'm trying to determine the name of the algorithm which will determine if a set of blocks listed as Xl,Yl-X2Y2 are part of a contiguous larger block. I'm just really looking for the name of, so I can go pull it out the NAG library. Bob. ...

Averaging angles... Again

I want to calculate the average of a set of angles, which represents source bearing (0 to 360 deg) - (similar to wind-direction) I know it has been discussed before (several times). The accepted answer was Compute unit vectors from the angles and take the angle of their average. However this answer defines the average in a non intuitiv...

Julianday get day of year

I have julianday like 731831, how i can get day of year from it? ...

Need Assembly Programming Help (TASM) - Booth's Algorithm

I've written an algorithm to simulate Booth's Algorithm using only Add, Sub, and Logical Operators and return a hexadecimal value. My Tasm compiler keeps throwing me these errors. When I try to omodify the code, it still doesn't work. Could someone help me out please. (29) Extra characters on line (38) Illegal immediate (44) Ille...

Tournament graph

A tournament is a directed graph (digraph) obtained by assigning a direction for each edge in an undirected complete graph. That is, it is a directed graph in which every pair of vertices is connected by a single directed edge. Data structure is adjacency matrix. What s an algorithm to find if the graph is a tournament graph? ...

Dynamic Programming: Sum-of-products

Let's say you have two lists, L1 and L2, of the same length, N. We define prodSum as: def prodSum(L1, L2) : ans = 0 for elem1, elem2 in zip(L1, L2) : ans += elem1 * elem2 return ans Is there an efficient algorithm to find, assuming L1 is sorted, the number of permutations of L2 such that prodSum(L1, L2) < some pr...

Lock Free Deque that supports removing an arbitrary node

This needs to be lock free as it has to run in the interrupt handler of an SMP system. I cannot take locks. I have a contiguous array holding some values. Some of the entries in this array are "free", they are not occupied. I want to make a list of these entries so that I can quickly allocate one. However, I occasionally have to allocat...