Is there any very fast method to find a binary logarithm of an integer number? For example, given a number
x=52656145834278593348959013841835216159447547700274555627155488768 such algorithm must find y=log(x,2) which is 215. x is always a power of 2.
The problem seems to be really simple. All what is required is to find the position of...
I have a whole bunch of percentages stored as XX% (e.g. 12%, 50%, etc..) I need to remove the percentage sign and then multiply the percent against another variable thats just a number (e.g. 1000, 12000) and then output the result. Is there a simple way to strip the percentage sign and then calculate the output with PHP? Or should I cons...
I was given a task. Write an algorithm so that, the input of 2 lists of data, will have at least one in common.
So, this is my algorithm: (I write the code in php)
$arrayA = array('5', '6', '1', '2', '7');
$arrayB = array('9', '2', '1', '8', '3');
$arrayC = array();
foreach($arrayA as $val){
if(in_array($val, $arrayB)){
ar...
Just wondering if there was a nice (already implemented/documented) algorithm to do the following
Given any shape (without crossing edges) and two points inside that shape, compute all the paths between the two points such that all reflections are perfect reflections. The path lengths should be limited to a certain length otherwise ther...
Hi everyone,
I'm searching for an algorithm to calculate the average distance between a point and a line segment in 3D. So given two points A(x1, y1, z1) and B(x2, y2, z2) that represent line segment AB, and a third point C(x3, y3, z3), what is the average distance between each point on AB to point C?
I'm also interested in the averag...
So I found some similarities between arrays and set notation while learning about sets and sequences in precalc e.g. set notation: {a | cond } = { a1, a2, a3, a4, ..., an} given that n is the domain (or index) of the array, a subset of Natural numbers (or unsigned integer). Most programming languages would provide similar methods to arra...
hi guys,
i'm looking for the fastest way to do an integer division in php. for example, 5 / 2 schould be 2 | 6 / 2 should be 3 and so on. if i simply do this, php will return 2.5 in the first case, the only solution i could find was using intval($my_number/2) - wich isn't as fast as i want it to be (but gives the expected results).
can...
Hello,
I have a value range from 0 to 255.
There is a method that returns an array with a min and max values within this range, i.e: 13, 15, 20, 27, 50 ... 240
where 13 is the min and 240 is the max
I need to scale these values so that 13 becomes 0 and 240 becomes 255 and scale all the other values between them proportionally.
Is ther...
Is there an online tool for adding parentheses to simple math equations? For example,
a + b * c
into
a + (b * c)
Those who paid more attention in math class might be able to tackle order of operations for huge equations in their head, but I could often use some help (and verification of my thinking).
I often encounter other peo...
What is the simplest way to calculate the amount of even numbers in a range of unsigned integers?
An example: if range is [0...4] then the answer is 3 (0,2,4)
I'm having hard time to think of any simple way. The only solution I came up involved couple of if-statements. Is there a simple line of code that can do this without if-statemen...
I would like to compute both the sine and co-sine of a value together (for example to create a rotation matrix). Of course I could compute them separately one after another like a = cos(x); b = sin(x);, but I wonder if there is a faster way when needing both values.
Edit:
To summarize the answers so far:
Vlad said, that there is the a...
I have code similar to:
if conditionA(x, y, z) then doA()
else if conditionB(x, y, z) then doB()
...
else if conditionZ(x, y, z) then doZ()
else throw ShouldNeverHappenException
I would like to validate two things (using static analysis):
If all conditions conditionA, conditionB, ..., conditionZ are mutually exclusive (i.e. it ...
I have a BigInteger value, let's say it is 282 and is inside the variable x. I now want to write a while loop that states:
while b2 isn't a perfect square:
a ← a + 1
b2 ← a*a - N
endwhile
How would I do such a thing using BigInteger?
EDIT: The purpose for this is so I can write this method. As the article states one must chec...
How can I get the 2 biggers numbers of a matrix row?
If the matrix have a bigger number in other row, it can't be shown.
For example, let's suppose I have the following matrix
int mat[][] ={{1,2,3}{4,5,6}{7,8,9}};
if I search the 2 biggers numbers from the row 0, it should return me the indexes 1 and 2 (values 2 and 3).
...
I am working on a factorisation problem and for small numbers it is working well. I've been able to calculate the factors (getting the answers from Wolfram Alpha) for small numbers, like the one on the Wikipedia page (5959).
Along with the Wikipedia page I have been following this guide. Once again, as my Math knowledge is pretty poor I...
I want to draw some items on screen, each item is in one of N sets. The number of sets changes all the time, so I need to calculate N different colours which are as different as possible (to make it easy to identify what is in which set).
So, for example with N = 2 my results would be black and white. With three I guess I would get all ...
Im working in a screen coordinate space that is different to that of the classical X/Y coordinate space, where my Y direction goes down in the positive instead of up.
Im also trying to figure out how to make a Circle on my screen always face away from the center point of the screen.
If the center point of my screen is at x(200) y(300) ...
Hi all, in the program I'm working on I have 3-element arrays, which I use as mathematical vectors for all intents and purposes.
Through the course of writing my code, I was tempted to just roll my own Vector class with simple +, -, *, /, etc overloads so I can simplify statements like:
for (int i = 0; i < 3; i++)
r[i] = r1[i] - r...
I've been looking at face detection lately, and a lot of the literature states their outputs have a range. How is this possible? I've created my own network and it only seems to be outputting either -1 or 1. Is this because I'm using the Tanh activation function? I want the values to output from, say, 0 to 1 in a range, rather than a ...
I found a similar question about getting just the rotation, but as I understand scaling and rotating work different in the transform matrix.
Matrixes are not my strength, so if anybody would hint me how to get only the scaling out of a CGAffineTransform I'd greatly appreciate.
btw. I tried applying the CGAffineTransform on a CGSize and...