math

Do I need to implement a b-tree search for this?

I have an array of integers, which could run into the hundreds of thousands (or more), sorted numerically ascending since that's how they were originally stacked. I need to be able to query the array to get the index of its first occurrence of a number >= some input, as efficiently as possible. The only way I would know how to do this ...

How to compute de Bruijn sequences for non-power-of-two-sized alphabets?

I'm trying to compute de Bruijn sequences for alphabets which have a number of characters which is not a power of two. For alphabets with a 2^k characters, calculating de Bruijn sequences is easy: There are several simple rules, such as "Prefer Ones" and "Prefer Opposites" which work for generating B(2,n). B(2^k,n) is exactly the same a...

Programming two trains to intersect without positional data or communication (logic puzzle)

A helicopter drops two trains, each on a parachute, onto a straight infinite railway line. There is an undefined distance between the two trains. Each faces the same direction, and upon landing, the parachute attached to each train falls to the ground next to the train and detaches. Each train has a microchip that controls its motion....

what is 57^46 divide by 17 ??

Hi all, 57^46 divide by 17 What is best and quickest way to solve such kind of problem manually? Approximate answer will do. ...

What's the opposite of JavaScript's Math.pow ?

I'm having a mental block here, and algebra not really being my thing, can you tell me how to re-write the JavaScript code below to derive the variable, c, in terms of a and b?: a = Math.pow(b, c); c = ? Thanks! ...

Smooth transition from 3D to 2D

I'm writing my own 3D engine and I have this matrix to make a perspective look. (It's a standard matrix so there is nothing interesting) public static Matrix3D PrespectiveFromHV(double fieldOfViewY, double aspectRatio, double zNearPlane, double zFarPlane, double mod) { double height = 1.0 / Math.Tan(fieldOfViewY / 2.0); ...

calculating modulo for large number

All, How can I calculate 2^301 mod 77? I did check out the link StackOverflow. But did not understand the step wherein 625 mod 221 = 183 mod 221. How did the conversion take place? ...

Bivariate Kernel Density Estimator in Java

Hi, I'm writing some software in which I need to compute bivariate densities of an x-y grid. Are there any libraries that might help me in Java for this? I've seen a lot of stuff in R, but nothing in Java. Thanks, Jeff ...

Why does Math.Exp give different results between 32-bit and 64-bit, with same input, same hardware

I am using .NET 2.0 with PlatformTarget x64 and x86. I am giving Math.Exp the same input number, and it returns different results in either platform. MSDN says you can't rely on a literal/parsed Double to represent the same number between platforms, but I think my use of Int64BitsToDouble below avoids this problem and guarantees the sa...

Cryptographically secure additive hash function

I am working on a Fountain Code based file transfer system. In this system blocks of data are downloaded, combined with an xor function. I want to verify the blocks as they arrive. What I need is a cryptographically secure hash function which has the property: Hash(A) ^ Hash(B) == Hash(A ^ B) does such a thing exist? Note: The data b...

Process mathematical equations in php

A user is allowed to enter any mathematical equation they like (with one variable): x + 5 1 - x/2 (x/3) * (56/13) These are stored as strings in the database. When they are retrieved I need to substitute 'x' for a number and check the value of the equation. How could I do this? I was considering writing a parser to deconstruct the...

Finding if something is within a range programmatically.

I know this is a simple math problem but for some reason im drawing a blank. If I have two ints which are boundaries for a range: int q = 100; int w = 230; and then another in that is a number that I want to see if it is inside of the range: int e = ?; How can I find if e is in the bounds of q and w? ...

What is the right precedence of the math expression

What is the correct sequence of the math operations in this expression in Java: a + b * c / ( d - e ) 1. 4 1 3 2 2. 4 2 3 1 I understand that result is the same in both answers. But I would like to fully understand the java compiler logic. What is executed first in this example - multiplication or the expr...

How do I effectively calculate zoom scale?

I have a draggeable image contained within a box. You can zoom in and zoom out on the image in the box which will make the image larger or smaller but the box size remains the same. The box's height and width will vary as the browser is resized. The top and left values for the image will change as it is dragged around. I'm trying to kee...

Implementing primality test in Java using BigInteger

I am trying to implement either the Fermat, Miller-Rabin, or AKS algorithm in Java using the BigInteger class. I think I have the Fermat test implemented except that the BigInteger class doesn't allow taking BigIntegers to the power of BigIntegers (one can only take BigIntegers to the power of primitive ints). Is there a way around this...

Intensional and extensional definition of sets

Hi, I am searching for a extensional definition for the following set: E := { m | m subset {a,b,c,d} and |m| = 2} My idea is E := {{a,b}, {a,c}, {a,d}, {b,c}, {b,d}, {c,d}, {a,a}, {b,b}, {c,c}, {d,d}} any ideas? ...

Implementation of Fermat's primality test in Java

Who wants to help me with my homework? I'm try to implement Fermat's primality test in Java using BigIntegers. My implementation is as follows, but unfortunately it doesn't work. Any ideas? public static boolean checkPrime(BigInteger n, int maxIterations) { if (n.equals(BigInteger.ONE)) return false; BigInteger a; ...

Algorithm for matching all items with another item in same list, where some have restrictions

Given array [a, b, c, d, e, f] I want to match each letter with any other letter except itself, resulting in something like: a - c b - f d - e The catch is that each letter may be restricted to being matched with one or more of the other letters. So let's say for example, a cannot be matched with c, d c cannot be matched with e,...

Finding the endpoint of a vertex given startpoint of vertex and midpoint of shape

Given that: The shape is a regular polygon in 3D space The start point (the end of one arbitrary vertex of the shape) is known the point in the middle of the shape (not on an edge - equidistant from all corners) is known the angle at each corner (((numEdges-2)*PI)/numEdges), the radius of the shape (distance from a corner to the midp...

Next Closest Pair Problem

I'm sure most are familiar with the closest pair problem, but is there another alogrithm or a way to modify the current CP algorithm to get the next closest pair? ...