Hi, I've been working on topcoder recently and I stumbled upon this question which I can't quite make understand.
The question is to find F(n) = f(1)+f(2)+....+f(n) for a given "n" such that f(n) is the largest odd divisor for n.
There are many trivial solutions for the answer; however, I found this solution very intriguing.
int comput...
I am trying to write a prime number function in C# and I am wondering if the follow code will work. It "appears" to work with the first 50 numbers or so. I just want to make sure it will work no matter how big the number is:
static bool IsPrime(int number)
{
if ((number == 2) || (number == 3) || (number == 5) || (number == 7) || (nu...
I'm doing some queries that require a lot of joined rows have some of their fields added and multiplied together.
I know it is sort of vague, but my question is which numeric data type is fastest for these types of operations?
Will FLOAT be faster than DOUBLE since DOUBLE is 8 bytes, and FLOAT is 4?
Will INT be faster than FLOAT (ev...
How can I round a number to the nearest X value (for example 50)
i.e
47 would be 50
24 would be 0
74 would be 50
99 would be 100
etc...
I really have no idea where to start looking into how to do this...
P.S. Im using cocoa-touch for the iPhone
Thanks a lot
Mark
...
Hi there,
I was wondering how can I get the inverse of power in ruby?
2 ** 4 => 16
and then I would like to get the inverse of it, and I'm not sure which operator to use :(
16 ?? 2 => 4
Thanks a lot
...
I have nearly 180 equations having nearly 550 variables.Can i solve this multivariable equations on 3.2Ghz and 4GB RAM maschine?Anybody have idea ,How many operations will it involve and how much time it will take?
...
I'm trying to calculate triangles base on the Area and the angles. If Angle-B is 90° then the formula works, but in my case, the angle can be from 0.1° to 179.8°. The formula assumes that the angle is 90, so I was thinking that there might be something that is hidden that could work for very angle. Here is the formula:
The formula in...
I seem to handle special cases like this somewhat frequently. There's got to be a more concise syntax or construct:
var x = solveForX(); /* some slow calculation here */
if (x < 0)
{
x = 0;
}
This is equivalent, but doesn't feel any more elegant:
var x;
x = (x = solveForX()) < 0 ? 0 : x;
Maybe there's a bit shift trick?
Upda...
I'm trying to find a root of a function that may be immediately before it begins having only imaginary values. (Specifically, it's the intersection of a line and a half-circle.) Obviously neither Brent's nor the bisection method will work; neither will Newton's method. Is there a less-obvious one that will?
...
I'm looking for a packing algorithm which will reduce a regular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge).
If possible, the answer to this question should explain the general heuristics...
Problem: Suppose you have a collection of points in the 2D plane. I want to know if this set of points sits on a regular grid (if they are a subset of a 2D lattice). I would like some ideas on how to do this.
For now, let's say I'm only interested in whether these points form an axis-aligned rectangular grid (that the underlying lattice...
Given n squares with edge length l, how can I determine the minimum radius r of the circle so that I can distribute all squares evenly along the perimeter of the circle without them overlapping? (Constraint: the first square will always be positioned at 12 o'clock.)
Followup question: how can I place n identical rectangles with height h...
This is more of a maths/general programming question, but I am programming with PHP is that makes a difference.
I think the easiest way to explain is with an example.
If the range is between 1 and 10.
I want to generate a number that is between 1 an 10 but is more likely lower than high.
The only way I can think is generate an array ...
I'm looking for a packing algorithm which will reduce an irregular polygon into rectangles and right triangles. The algorithm should attempt to use as few such shapes as possible and should be relatively easy to implement (given the difficulty of the challenge). It should also prefer rectangles over triangles where possible.
If possibl...
Hello,
I'd like to create a function which will generate a 3 char key string after each loop.
There are 26 chars in the alphabet and I'd like to generate totally unique 3 char keys (A-Z).
The output would be 17,576 unique 3 char keys (A-Z) - not case sensitive.
Can anyone give me an idea on how to create a more elegant function witho...
(Apologies in advance. My math skills and powers of description seem to have left me for the moment)
Imagine a cube on screen with a two sets of controls. One set of controls to rotate the cube side to side (aka yaw or Y or even Z depending on one's mathematical leanings) and another set of controls to rotate up and down (aka pitch or X)...
I'm creating a simple 2D game in javascript/canvas.
I need to figure out the angle of a certain object relative to my position.
So: say I'm at (10,10) and the object is at (10,5) - that would result in 90 degrees (as positive Y is down, negative Y is up)
(10,10) vs (10,15) would be 270 degrees.
How would I go about this?
...
I have a camera mounted on a tripod its motion is restricted to pan and tilt rotation. It is looking at dot that is at a known location directly in front of the camera. If the camera looks at the dot and gets the 2d coordinate of it, is it possible to deduce the camera's rotation so that I can overlay some 3d models properly aligned to...
I have seen programmers "battling" it out with really complex mathematical problems in their codes, particularly in the fields of game programming, physics programming, graphics programming, etc. I am a web developer, and I wonder if there are math concepts out there that I can use for web programming. I started web programming a year an...
It seems that simple comparison signs >,>= and their reverse components can evaluate if a certain variable is a number or not. Example $whatami='beast'; ($whatami<0)?echo 'NaN':echo 'is numeric!';
Are there cases where is_numeric() usage is necessary for positive values (number >0)? It seems that using comparison signs above would deter...