math

Count bits used in int

If you have the binary number 10110 how can I get it to return 5? e.g a number that tells how many bits are used? There are some likewise examples listed below: 101 should return 3 000000011 should return 2 11100 should return 5 101010101 should return 9 How can this be obtained the easiest way in Java? I have come up with the follow...

Find all ways to insert zeroes into a bit pattern

I've been struggling to wrap my head around this for some reason. I have 15 bits that represent a number. The bits must match a pattern. The pattern is defined in the way the bits start out: they are in the most flush-right representation of that pattern. So say the pattern is 1 4 1. The bits will be: 000000010111101 So the genera...

finding ALL cycles in a huge sparse matrix

Hi there, First of all I'm quite a Java beginner, so I'm not sure if this is even possible! Basically I have a huge (3+million) data source of relational data (i.e. A is friends with B+C+D, B is friends with D+G+Z (but not A - i.e. unmutual) etc.) and I want to find every cycle within this (not necessarily connected) directed graph. I...

Transformation to get rid of collinear points

Hi, I'm writing a program to solve a geometry problem. My algorithm doesn't treat collinear point very well. Is there any transformation I can apply to the points to get rid of the collinearity? ...

Clustering [assessment] algorithm with distance matrix as an input

Can anyone suggest some clustering algorithm which can work with distance matrix as an input? Or the algorithm which can assess the "goodness" of the clustering also based on the distance matrix? At this moment I'm using a modification of Kruskal's algorithm (http://en.wikipedia.org/wiki/Kruskal%27s_algorithm) to split data into two clu...

Rock Paper Scissors for arbitrary odd number of elements

How do I efficiently create a rock-scissors-paper game for n elements, where n is any odd number >=3. In other words, I want a non-transitive complete ordering of n elements such that each element is greater than (n-1)/2 other elements and each element is lesser than (n-1)/2 other elements. ...

Math - Adding with PHP

Basically I can't get it right. I need something like this: if($p == 1) { $start = 0; $limit = 16; } The numbers must add on depending on the value of the $p, e.g. if $p is 5 then the values of $start and $limit would be: if($p == 5) { $start = 64; $limit = 80; } The math is to add 16, depending on the value of $p....

How to simplify fractions in C#?

I'm looking for a library or existing code to simplify fractions. Does anyone have anything at hand or any links? P.S. I already understand the process but really don't want to rewrite the wheel Update Ok i've checked out the fraction library on the CodeProject BUT the problem I have is a little bit tricker than simplifying a fracti...

Silverlight - round doubles away from zero

In Silverlight the Math.Round() method does not contain an overload with 'MidpointRounding' parameter. What is the best approach to round a double away from zero in Silverlight in this case? Example: Math.Round(1.4) => 1 Math.Round(1.5) => 2 Math.Round(1.6) => 2 ...

Best way to add the minus "-" front of decimal value

I would like to ask how i should add the minus sign front of a decimal value. i want the user to add e.g. 100 and behind the scenes to convert it in -100 thank you. ...

What's the easiest way to work out the difference between two positive integers?

I just need to know the difference between two int variables a and b. I'm new to Objective-C. ...

How to detect if an ellipse intersects(collides with) a circle

I want to improve a collision system. Right now I detect if 2 irregular objects collide if their bounding rectangles collide. I want to obtain the for rectangle the corresponding ellipse while for the other one to use a circle. I found a method to obtain the ellipse coordinates but I have a problem when I try to detect if it intersect...

C++ fixed point library?

I am looking for a free C++ fixed point library (Mainly for use with embedded devices, not for arbitrary precision math). Basically, the requirements are: No unnecessary runtime overhead: whatever can be done at compile time, should be done at compile time. Ability to transparently switch code between fixed and floating point, with no ...

prove, that if sqr(a) + sqr(b) divisible on 7, then a + b divisible on 7 too

how can i prove, that if sqr(a) + sqr(b) divisible on 7, then a + b divisible on 7 too. i'm thinking on it whole day... Thanks update i mean, that sqr(a) = a*a ...

Inner angle between two lines

Hi folks, I have two lines: Line1 and Line2. Each line is defined by two points (P1L1(x1, y1), P2L1(x2, y2) and P1L1(x1, y1), P2L3(x2, y3)). I want to know the inner angle defined by these two lines. For do it I calculate the angle of each line with the abscissa: double theta1 = atan(m1) * (180.0 / PI); double theta2 = atan(m2) * (18...

intersecting line and array of points?

hi, i am having a line in normal graph,i want to know intersecting some points with that line , any formula for it?any help please? The line is from startpoint(50,50),endPoint(50,0)....the some point may be (0,10),(2,45),etc.. ...

Can someone explain how this works?

Key in the first three digits of your phone number (NOT the Area code...) Multiply by 80 Add 1 Multiply by 250 Add to this the last 4 digits of your phone number Add to this the last 4 digits of your phone number again. Subtract 250 Divide number by 2 Do you recognize the answer?? ...

Missing Coordinates. Basic Trigonometry Help.

please refer to my quick diagram attached below. what i'm trying to do is get the coordinates of the yellow dots by using the angle from the red dots' known coordinates. assuming each yellow dot is about 20 pixels away from the x:50/y:250 red dot at a right angle (i think that's what it's called) how do i get their coordinates? i beli...

How to calculate amount of contingency tables?

If i want to calculate the amount of k-dimensional contingency tables which formula should I use? For example, if i have 16 categorical variables in my dataset and want to calculate the amount of 1-dimensional contingency tables, then it's clear, there is only 1 table. If I want to calculate the amount of 2-dimensional contingency table...

0.699 x 100 = 69.89999999999999 ?

Possible Duplicates: Why does 99.99 / 100 = 0.9998999999999999 Dealing with accuracy problems in floating-point numbers I've seen this issue in php and javascript. I have this number: float 0.699 if I do this: 0.699 x 100 = 69.89999999999999 why? edit round(0.699 x 10, 2): float 69.90000000000001 ...