math

How to sum array members in Ruby?

I have an array of integers. For example: array = [123,321,12389] Is there any nice way to get the sum of them? I know, that sum = 0 array.each { |a| sum+=a } would work. ...

Obscure VBMath random numbers generator behavior.

Hi, I want to repeat a random number sequence generated by a legacy software using the VBMath.Rnd and VBMath.Randomize functions in VB .NET Reading on the documentation for those functions on MSDN i found that you are supposed to "reset" the generator calling Rnd with a negative value if you want the same seed to give you the same res...

Calculating very large whole numbers

I am trying to compute 2^1000 (2 to the power of 1000) using c#. I need the value to all places. I've been scratching my head for a while now because I can't seem to figure out a way to achieve this in c#. Is there some kind of type that will store a number 300+ digits long, that I'm missing? :) Thanks ...

Math Expression Evaluation

What is the best way to implement a python program that will take a string and will output its result according to operator precedence (for example: "4+3*5" will output 19). I've googled for ways to solve this problem but they were all too complex, and I'm looking for a (relatively) simple one. clarification: I need something slightly m...

Good computer science lecture series

Since we have a thread on books.. what are your recommendations of publicly accessible video lecture series related to programming, computer science, or mathematics? Please post specific courses, not websites with courses. :) This is the video equivalent of this thread: http://stackoverflow.com/questions/194812/list-of-freely-available...

silverlight math performance question

Is there some reason that identical math operations would take significantly longer in one Silverlight app than in another? For example, I have some code that takes a list of points and transforms them (scales and translates them) and populates another list of points. It's important that I keep the original points intact, hence the sec...

Octave: testing functions over a Range in Lists or like with For-loops?

I want to see the values of the function y(x) with different values of x, where y(x) < 5: y = abs(x)+abs(x+2)-5 How can I do it? ...

C# Nth Root of small number precision problem

When I try to take the N th root of a small number using C# I get a wrong number. For example when I try to take the 3rd root of 1.07, I get 1, which is clearly not true. Here is the exact code I am using to get the 3rd root. MessageBox.Show(Math.Pow(1.07,(1/3)).toString()); Can anyone tell me how to solve this problem. I would gue...

How can I learn higher-level programming-related math without much formal training?

I haven't taken any math classes above basic college calculus. However, in the course of my programming work, I've picked up a lot of math and comp sci from blogs and reading, and I genuinely believe I have a decent mathematical mind. I enjoy and have success doing Project Euler, for example. I want to dive in and really start learning ...

Check if mouse is over a rotated sprite? C++

I'm making a game in c++. It is a card game. I have made 13 cards that rotate about a point to arc out to make your hand. I need a way to figure out which card the user clicks on. My cards are basically rectangles rotated about a point that is in the center of the cards. I was thinking of maybe getting the mouse point and rotating it abo...

Looking for a good reference on calculating permutations

Hi, As a programmer, I frequently need to be able to know the how to calculate the number of permutations of a set, usually for estimation purposes. There are a lot of different ways specify the allowable combinations, depending on the problem at hand. For example, given the set of letters A,B,C,D Assuming a 4 digit result, how m...

Scale numbers to be <= 255?

I have cells for whom the numeric value can be anything between 0 and Integer.MAX_VALUE. I would like to color code these cells correspondingly. If the value = 0, then r = 0. If the value is Integer.MAX_VALUE, then r = 255. But what about the values in between? I'm thinking I need a function whose limit as x => Integer.MAX_VALUE is 25...

Intersection on circle of vector originating inside circle

I have a circle. Inside the circle is a point. I have a vector originating at this point. I'd like to know what point on the circle this vector intersects. Here is a drawing: The red dot is the point I am trying to determine. I know these things: the center of the circle, the origin of the vector, and the direction of the vector. I ...

Optimisations for a series of functions in Haskell

Hi I am trying to do problem 254 in project euler and arrived at this set of functions and refactor in Haskell: f n = sum $ map fac (decToList n) sf n = sum $ decToList (f n) g i = head [ n | n <- [1..], sf n == i] sg i = sum $ decToList (g i) answer = sum [ sg i | i <- [1 .. 150] ] Where: f (n) finds the sum of the factorials ...

How to check for division by 7 for big number in C++?

I have to check, if given number is divisible by 7, which is usualy done just by doing something like n % 7 == 0, but the problem is, that given number can have up to 100000000, which doesn't fit even in long long. Another constrain is, that I have only few kilobytes of memory available, so I can't use an array. I'm expecting the numbe...

3d maths in Flash AS3

I'm trying to code a 3d wall like http://www.flashloaded.com/flashcomponents/3dwall/ The shape I am looking to create is like a bath or arena where it is a curve cornered rectangle with sloping sides. The image below shows what i'm trying to achieve if viewed from above. I hope that helps. Can anyone give me some ideas on the maths ...

Points enclosed by a custom defined Hypercube

I have a N-dimensional vector, X and 'n' equidistant points along each dimension and a parameter 'delta'. I need a way to find the total of n^N vectors enclosed by the Hypercube defined with the vector X at the center and each side of Hypercube being of size 2*delta. For example: Consider a case of N=3, so we have a Cube of size (2*de...

Rounding to the Nearest Ending Digits

I have the following function that rounds a number to the nearest number ending with the digits of $nearest, and I was wondering if there is a more elegant way of doing the same. /** * Rounds the number to the nearest digit(s). * * @param int $number * @param int $nearest * @return int */ function roundNearest($number, $nearest, ...

Turning Random Number Into Deterministic White Noise

I need to be able to generate a single random number and then use that number to seed a theoretically infinitely large 2d plane on the fly with boolean values. I need a function I can call that is deterministic with three inputs (x, y, and the random seed) and returns a pseudo-random result back: int r = random() //... var value_for_poi...

3d Math Library For Python

i'm looking for a 3d math library in python or with python bindings. it needs to handle rotation, translation, perspective projection, everything basically. what im NOT looking for is a library aimed at drawing on the screen, googling for hours only led to 3d libraries bent on rendering something to the screen. i dont want any visuali...