Calculate the shortest route between two points

I have been working in the past weeks on a multiplayer HTML5 game, using nodejs and websockets. I've been stuck in this problem for a little while. Imagine that I have this tilesheet map implemented with an array (as shown below). 1 or brown tiles -

Mapping a 2D Table into a 1D Table with Variable Column Width

I know mapping 2D array into 1D array has been asked many times, but I did not find a solution that would fit a where the column count varies. So I want get a 1-dimensional index from this 2-dimensional array Col> _0____1____2__ Row 0 |_0__|_1__|_2__

Implement bit changes using only OR and AND

I want to implement SHL64 and SHR64 for my virtual CPU. My CPU have only four instructions implemented from NAND and can execute any if statements (all compare operations) Not Or And CMP (signed/unsigned/any type from 8b to 64b) Currently i implement

Find the number of times a report runs

I am told to figure out the number of times the statement foo runs in the following program. We are assuming that n is an even number. j = 1; while( j <= n/2 ) { i = 1; while( i <= j ) { foo; i++; } j++; } I figured the best way to go about this wou

Convert from one range to another

I have two sets of ranges that I need to be translated from one to the other. The first range is -100 ↔ 100 with 0 being default. The second range is 0.0 ↔ 10.0 with 1 being default. I am working in AS3 with the first range and the second range is a

How to generate a set of circle points from a point?

I'm in a situation that I have a point Vector3(x,y,z), and I need from that starting point to generate a circle in 3D (a ring) that starts with that point and ends with it. Right now I can generate a circle of vector3, but I don't know how to generat

How to find the largest integer less than x?

If x is 2.3, then math.floor(x) returns 2.0, the largest integer smaller than or equal to x (as a float.) How would I get i the largest integer strictly smaller than x (as a integer)? The best I came up with is: i = int(math.ceil(x)-1) Is there a bet

Compact storage coefficient of a multivariate polynomial

The setup I am writing a code for dealing with polynomials of degree n over d-dimensional variable x and ran into a problem that others have likely faced in the past. Such polynomial can be characterized by coefficients c(alpha) corresponding to x^al

Need different result in the rounded value in java

I am using following line of code to round off value in java public class FloorTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub System.out.println(Math.round(29.56)); System.out.println(Math.roun

Very high power in C ++

Can someone with a bit of time, he could explain to me how intensify very large numbers? I'm not talking here about a ready solution, and the only explanation of how to implement the arithmetic. Ideally, it was based on the class std::string. @edit I

Step Independent Llopper

I often smooth values by blending percentages and inverse percentages with the below: current_value = (current_value * 0.95f) + (goal_value * 0.05f) I'm running into a situation where I would like to perform this action n times, and n is a floating p

Linear interpolation of three 3D points in 3D space

I have three 3D points like p1(x1,y1,z1), p2(x2,y2,z2), p3(x3,y3,z3). I have another point, but I know only x, y value of that point like p4(x4,y4,Z), in which Z is the value I like to compute. I am sure p4(x4,y4) point is inside a triangle formed by

setting up a cantor matching function in iOS

I have a implementation of the Cantor Pairing Function in Java which I wrote 2 years ago. Now then I'm moving more to iOS I need the same thing in Objective-C. The problem is, at least from my point of view, in Java I had to implement a BigSqrt Class

The fastest way to get a number of digits on a number?

This question already has an answer here: Way to get number of digits in an int? 27 answers I have do detect the amount of digits on a number. For example, 329586 has 6 digits. What I done, is simply parsing the number to string, and getting the stri

C special mathematical functions with bsd / mit-like license

are you aware of a trusted (i.e. efficient and accurate) implementation of special math functions (like gamma, beta, error and inverse error functions) for the C language available with a non-gpl license? BSD or MIT licenses are fine. So something li

How to simplify fractions?

How to simplify a fraction in C#? For example, given 1 11/6, I need it simplified to 2 5/6.If all you want is to turn your fraction into a mixed number whose fractional part is a proper fraction like the previous answers assumed, you only need to add

How to obtain the length of a segment crossing a square?

I have a line, defined by the parameters m, h, where y = m*x + h This line goes across a grid (i.e. pixels). For each square (a, b) of the grid (ie the square [a, a+1] x [b, b+1]), I want to determine if the given line crosses this square or not, and

How do I print the EXACT value of a floating-point number?

First of all, this is not a floating point newbie question. I know results of floating point arithmetic (not to mention transcendental functions) usually cannot be represented exactly, and that most terminating decimals cannot be represented exactly

Arrangement of n objects in a square n × n

if have multiples object, how to arrange it so that each number of object in row x column will form a near square? exp:14 objects arrange to something like this: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Take the ceil of the square root? in python: import math cei

Polarized change in percentage values

differencePercentage = Math.round(((Pay.init / Pay.current) * 100) - 100); and that gives me the difference in percent between initial and current pay, but it's reversed. When it's positive i.e. pay is above the initial value it says -X%, and when it

Find a point between two points

I two concentric circles on the screen and I want the circle on the inside to move around while the user drags their finger around the outside of the larger circle. This means that I have two point, center of the larger circle and the point at which

I have a structure, but I do not know how to use it

typedef struct Complex{ double real; int img; } Complex; I've seen people use it as a type like: Complex sqrt( double x) { } how do 'real' and 'img' play a role in this type of function? ThanksIt can be used like this: Complex sqrt(double x) { Comple

Unit-specific square roots

I just wondered how it is possible to write a user-defined square root function (sqrt) in a way that it interacts properly with F#'s unit system. What it should be like: let sqrt (x : float<'u ^ 2>) = let x' = x / 1.0<'u ^ 2> // Delete unit (x

Calculate VAT in SQL

How do you write a SQL query to calculate the VAT and then add it to Total?Surely homework. However, let us know what you've tried. In general, you're supposed to make an effort first before people on SO will help you. What does your table look like?