math

Algorithm to fill slots

I am searching for an algorithm to fill several slots, which are already filled to some level. The current levels and the available quantity to fill are known Resulting levels should be as equal as possible, but existing level cannot be reduced Slots are filled from left to right, so left slots get higher level if equal level is imposs...

Interesting task using random numbers only

Given any number of the random real numbers from the interval [0,1] is there exist any method to construct a floating point number with zero fractional part? Your algorithm can use only random() function calls and no variables or constants. No constants and variables are allowed, no type casting is allowed. You can use for/while, if/el...

Computing complex math equations in python

Are there any libraries or techniques that simplify computing equations ? Take the following two examples: F = B * { [ a * b * sumOf (A / B ''' for all i ''' ) ] / [ sumOf(c * d * j) ] } where: F = cost from i to j B, a, b, c, d, j are all vectors in the format [ [zone_i, zone_j, cost_of_i_to_j], [..]] This should produce a vecto...

Vector Calculations in LISP

How can I perform vector calculations in lisp, such as magnitude of a vector, norm of a vector, distance (between two points), dot product, cross product, etc. Thanks. ...

Fastest method to define whether a number is a triangular number

A triangular number is the sum of the n natural numbers from 1 to n. What is the fastest method to find whether a given positive integer number is a triangular one? ...

How to know if two stocks move togheter?

Hello, I have two stocks with their prices, example: STOCK1: 10.56 11.23 12.32 8.90 STOCK2: 1.26 5.80 3.26 10.3 I only found Pearson correlation, but, is there another method to know if two stocks move togheter? (esample: co-integration??) Thank you so much! ...

How can I scale multiple windows with fixed aspect ratio so that they cover maximum of monitor without overlapping

My question is in my title. I am trying to develop a logic so that I can scale fixed aspect ratio windows to cover most of the screen without overlapping eachother. There could be two three or four windows. There could be an alignment parameter also. ...

Sliding & Fading controls on a C# form

Hey there, I'm trying to implement a way to slide&fade controls around (more than one at the same time possibly) elegantly. So in other words, say i had a picture in the top left corner, and a texbox in the bottom right corner, i'd like to be able to have them slide. not just snap. slide, to the opposite corners and replace eachothers po...

Algorithm to calculate a page importance based on its views / comments

I need an algorithm that allows me to determine an appropriate <priority> field for my website's sitemap based on the page's views and comments count. For those of you unfamiliar with sitemaps, the priority field is used to signal the importance of a page relative to the others on the same website. It must be a decimal number between 0 ...

Find current value of a variable that depreciates linearly over time

Let's say we have an empty bathtub. We've lost the plug, so once water is added it will drain away at a constant rate of 2 liters pr. minute. We add water to the tub in increments. 60 liters at 10:51, 30 liters at 11:54 and 50 liters at 13:18. So, the question is: How can I find out how much water is in the bathtub at any given time? ...

Obtain Latitude and Longitude from a GeoTIFF File

Using GDAL in Python, how do you get the latitude and longitude of a GeoTIFF file? GeoTIFF's do not appear to store any coordinate information. Instead, they store the XY Origin coordinates. However, the XY coordinates do not provide the latitude and longitude of the top left corner and bottom left corner. It appears I will need to d...

Histogram matching - image processing - c/c++

Hello I have two histograms. int Hist1[10] = {1,4,3,5,2,5,4,6,3,2}; int Hist1[10] = {1,4,3,15,12,15,4,6,3,2}; Hist1's distribution is of type multi-modal; Hist2's distribution is of type uni-modal with single prominent peak. My questions are Is there any way that i could determine the type of distribution programmatically? How ...

Calculating an NxN matrix determinant in C#

How do you calculate the determinant of an NxN matrix C# ? ...

Doubling binary digits

How to double a number of binary digits in an integer? For example, if bin(x)="1001" then bin(y) must be "11000011". Is there any smart and fast algorithm ? UPDATE: Here is an elegant solution: ''.join([''.join(i) for i in zip(X,X)]) where X is bin(int_x)[2:] However, I am interested in a more faster way and for the integers of any...

How to detect if a certain range resides (partly) within an other range?

Lets say I've got two squares and I know their positions, a red and blue square: redTopX; redTopY; redBotX; redBotY; blueTopX; blueTopY; blueBotX; blueBotY; Now, I want to check if square blue resides (partly) within (or around) square red. This can happen in a lot of situations, as you can see in this image I created to illustrate my...

Math algorithm question

I'm not sure if this can be done without some determining factor....but wanted to see if someone knew of a way to do this. I want to create a shifting scale for numbers. Let's say I have the number 26000. I want the outcome of this algorithm to be 6500; or 25% of the original number. But if I have the number 5000, I want the outcome ...

Fastest way to find the rotation of a vector

I have two 2D vectors, say u and v, defined by cartesian coordinates. Imagine that vectors are needles of a clock. I'm looking for the fastest way to find out, using python, if v is after or before u (or in other words find out in wich half plane is v, regarding to position of u). For the purpose of the problem if vectors are aligned an...

What Math topics & resources to consider as beginner to indulge the book - Introduction to Algorithms (CLRS)?

I'm a programmer who's beginning to appreciate the knowledge & usability of Algorithms in my work as I move forward with my skill-set. I don't want to take the short path by learning how to apply algorithms "as-is" but would rather like to know the foundation and fundamentals behind them. For that I need Math, at which I'm pretty "basic"...

Determining if two rays intersect

I have two rays on a 2D plane that extend to infinity but both have a starting point. They are both described by a starting point and a vector in the direction of the ray extending to infinity. I want to find out if the two rays intersect but i don't need to know where they intersect (its part of a collision detection algorithm). Everyt...

Math problem: Determine the corner radius of an inner border based on outer corner radius/thickness

Here's a math/geometry problem for the math whizzes (not my strongest subject). This is for WPF, but should be general enough to solve regardless: I have two embedded Border elements, with the outer one having a certain corner radius, R and border thickness, T. Given these two values, what should the corner radius of the inner Border, R...