## [Solved] How to solve this mathematical equation in php [closed]

Just group the D’s first and dont hardcode the indices, use \$i \$S = array(); \$D = array(); \$M = array(“1″=>30,”2″=>31,”3″=>30); \$Y = array(“1″=>360,”2″=>360,”3″=>360); \$O = 30000; \$P = 0.3; \$N = 10509.74; for(\$i = 1, \$size = count(\$M); \$i <= \$size; \$i++){ \$final_D = 0; // group the D’s first (O-D1), (O-D1-D2), … and … Read more

## [Solved] Why is my code miscalculating the total force from a list of (magnitude, angle) pairs? [closed]

from math import sqrt, sin, cos, atan2, degrees, radians def find_net_force(forces): h_force = sum( [ force * cos(radians(force)) for force in forces ] ) v_force = sum( [ force * sin(radians(force)) for force in forces ] ) r_force = round(sqrt((h_force ** 2) + (v_force ** 2)), 1) r_angle = round(degrees(atan2(v_force, h_force)), 1) return (r_force, r_angle) … Read more

## [Solved] How to make every ‘beginner’ shown at random during the run of the program [closed]

So this isn’t exactly an answer for the specific way you decided to go about this program but this is a much simpler way: from random import randrange def beginner_addition(): A = randrange(1,11) # Increase range on harder questions B = randrange(1,11) # Ex. for intermediate_addition(), randrange would be (10,21) maybe… C = A + … Read more

## [Solved] Why does floating-point arithmetic not give exact results when adding decimal fractions?

Binary floating point math is like this. In most programming languages, it is based on the IEEE 754 standard. The crux of the problem is that numbers are represented in this format as a whole number times a power of two; rational numbers (such as 0.1, which is 1/10) whose denominator is not a power … Read more

## [Solved] Convert loop into mathematical equation

for loop can be simplifed to x= (pow(3,n)-1)/2 I have double checked this here:http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29 3 solved Convert loop into mathematical equation

## [Solved] Formula for Mapping three values [closed]

With (val>>1)-(val & 1) you get your first result: 0 -> 0 1 -> -1 2 -> 1 The alternative result can be got with (val & 1)-(val>>1): 0 -> 0 1 -> 1 2 -> -1 0 solved Formula for Mapping three values [closed]

## [Solved] Generating all triples from a graph?

As discussed in the comments to the question, it’s not very clear exactly what epitaph‘s setup is, and for some reason s/he seems unwilling to clarify. But let’s suppose that the “graph” is actually simply represented by a distance matrix (which may possibly be what the mess of numbers and Xs in the question is … Read more

## [Solved] Cannot find the value of X in Java 42L + -37L * X == 17206538691L

It’s not completely clear what you are looking for, but note that java long arithmetic is effectively done mod 264. You can investigate modular inverses and the extended euclidean algorithm yourself, as well as how java handles integer overflow. The BigInteger class makes doing these experiments relatively easily, as this example shows. public class Main … Read more

## [Solved] Why is this while loop an infinite loop? High school introduction to CS exam review [closed]

You’re not updating the value of b inside the loop, so its value is always 6. You need to use an assignment operator to actually set a new value. So, use b = b + 3; or b += 3; instead. 1 solved Why is this while loop an infinite loop? High school introduction to … Read more

## [Solved] How to generate Random point(x,y) in Java [closed]

Take a look at article https://www.tutorialspoint.com/java/util/java_util_random.htm. All you need to do is to generate pairs of floats in range (-1,1). You should use method nextFloat() from class Random. It will give you numbers in range (0,1). Then multiply it by 2 and subtract 1 and you will have numbers in desired interval. 0 solved How … Read more