I have the shunting yard algorithm that I found online: import java.util.HashMap; import java.util.Map; import java.util.Stack; public class ShuntingYardAlgorithm { private enum Operator { ADD(…
Tag: math
Determining divisibility of number by 11 for large numbers
I’m looking for a way to determine a large number is divisible by 11 My understanding: (sum of digits at even positions – sum of digits at odd positions) % 11 == 0 ==> yes This works for some examples. Example: 3816 => (3+1) – (8+6) = -10 In case of negative, do we need to consider 2’s complement of
BigDecimal gives unexpected results for numbers larger than 7 or 0 decimal numbers
While trying to calculate a ratio of the volume of 2 objects, I noticed some weirdness in the calculation, here is a sample you can run for yourself: And the result is: There are 3 ways I could make it give me the expected result 1. If I change the decimal part from 0 to 1 (or any non-0 number):
Is there a numerical type (primitive or class) in Java that contains every other numerical type?
Can any number be converted into a Double in Java ? If not, is there a Number class that could parse any numerical type and that would provide basic mathematical operations ? I have numbers that can be either int, double, float, long, unsigned float or unsigned long. If I could just call them “Number” it will be easier as
Get 3D coordinates of vertices of rotated and scaled cuboid with scale, center position and rotation on all axis
I have been wrecking my brain trying to figure out this problem I have. I have a cuboid, its rotation on all 3 axis in relation to the world from its center (it’s on 3D space), the cuboid’s center’s position and the scale of the cube in all axis (width, height and depth). I need to find the coordinates of
Rounding to 0.05 taxes what am I doing wrong?
I’m super stuck on this problem and I don’t know where the math is going wrong. here goes.. Calculate the tax on these 2 products. tax should be rounded to the nearest 0.05. product_ONE price = $47.50 with a tax of 15%—answer should be $54.65; 47.50 * 15 / 100 = 7.125 7.125 / 0.05 = 142.5 -> rounded you
How to chose a random point at a certain distance to a reference point
I have point A (pointA = (x1, y1)) and I need to choose a random point B (pointB = (x2, y2)) such that the distance between the A and B is equal to K. Answer Let’s solve in polar form. We’ll need these doubles distance, x1, and y1. First, we want the angle in radians: Then we want to get
Closest divisible integer
Example. How can I find the integer c? The result of that example is c = 250. Answer There are two cases to consider: The closest integer that is less than or equal to a: The closest integer that is greater than a: Then we need to check which is closer to a and return that: So we could create
Find closest factor to a number, of a number
I am trying to automate the finding of the closest factor of a number to another number; Example: Closest factor of 700 to 30 is 28 (30 does not go into 700, but 28 does). An obvious solution is just to get all the factors of 700 and do a simple distance calculation to find the nearest factor to 30,
Calculate the date of Easter Sunday
Write a program to compute the date of Easter Sunday. Easter Sunday is the first Sunday after the first full moon of spring. Use the algorithm invented by the mathematician Carl Friedrich Gauss in 1800: Let y be the year (such as 1800 or 2001) Divide y by 19 and call the remainder a. Ignore the quotient. Divide y by