Programming questions that are significantly affected or best defined by the underlying mathematics of the problem.

learn more… | top users | synonyms

-3
votes
0answers
57 views

Biggest palindromic number which is a product of two 3 digit numbers [on hold]

I've got to find the biggest palindromic number which is a product of two 3 digit numbers. I wrote a program for it in Java but something is going wrong. Here is the program I've written. public ...
4
votes
8answers
6k views

What specific branches of Mathematics are useful for a programmer to learn? [on hold]

I have less than 6 months to learn mathematics for my Master course in CS. (With no prior formal education in any computer/mathematics related area.) So I need to prepare my self to be tested on math ...
2
votes
1answer
81 views

Optimizing the exponential smoothing of a big array

I have a large set of values (let's say 1M entries) where I need to apply an exponential smoothing algorithm, but only incrementing one value at a time (all others decay to zero). The trivial ...
3
votes
1answer
192 views

Swapping variable values without creating a new one

Recently, I was faced with a question that asked me to swap variable values without creating an extra variable. i.e. A = 10, B = 20. How store 20 to A and 10 to B? The solution is: A = A + B ...
0
votes
1answer
74 views

Achieving permutation using recursion [on hold]

Though I like recursions and understand it, I fail to master it! I am stuck with a problem which I know that recursion can solve, but I do not know how. I have an array of strings like: "hundred", ...
-2
votes
3answers
118 views

How to create an algorithm for a raffle, where each raffle guarantees a winning ticket?

I am looking for an algorithm to create a raffle, where each participant is assigned a ticket with a random series of numbers. Each raffle hast N participants, and there should exist same amount of ...
1
vote
1answer
54 views

How to improve timeout value dynamically?

I'm working on an application where I want to keep a timeout value computed dynamically using a moving average of say 100 previous response times for service A. This value + some buffer (~3 seconds) ...
6
votes
4answers
190 views

Convert version string to integer

I need to be able to convert a version string to an integer. I've decided I will follow semantic versioning so version strings will be of the type x.y.z. Initially I thought a simple algorithm like ...
22
votes
4answers
22k views

Prerequisite math skill for Introduction to Algorithms (CLRS) book [closed]

I already have knowledge about basic algorithms. Now I plan to study more advance algorithms and I decide to go with Introduction to Algorithms. I'm not sure, do I need to refresh my math's skill ...
5
votes
5answers
11k views

Math Major wants to become a Software Engineer [closed]

I am a math major, what would be the best field of computer science/computer engineering for me to go into, where I could apply my skills that I used as a math major (i.e. Linear Algebra, Real ...
9
votes
3answers
328 views

When should a trig function, with a degree argument, return -0.0?

In creating trig functions my_sind(d), my_cosd(d), my_tand(d), that used a degree argument rather than a radian one and provided exact answers at multiples of 90, I noticed that the result was ...
1
vote
1answer
75 views

Question about the uses of matrices in games and 3D graphics [closed]

So I know that matrices are used extensively in the field of games and 3D graphics, for example, you need to know how to do matrix multiplication if you want to understand how scaling an object works, ...
2
votes
1answer
2k views

Randomly Generate Points in a Spiral Motion using Javascript

So I have a javascript program that currently gets random points, it generates a random x,y,z value around the center point, within the radius r var maxArms = 3; var i = 0; var color = []; ...
0
votes
0answers
37 views

Simplistic non-secure example of public key encryption

I'm giving a lecture to novice developers on security and would like to explain ssl and the basics of certificates. For this I would like to convey a vague intuitive understanding of asymmetric key ...
2
votes
2answers
7k views

Closest Point of Approach (CPA) mathematical formula in ship radar

I was recently searching for the mathematical formula to find closest point of approach (CPA) between one ship and another ship. I need to apply the formula in my radar ship program and I can't find ...
53
votes
5answers
7k views

Will a computer attempt to divide by zero?

We all know 0/0 is Undefined and returns an error if I were to put it into a calculator, and if I were to create a program (in C at least) the OS would terminate it when I try to divide by zero. But ...
41
votes
5answers
1k views

Why is negative zero important?

I'm confused about why we care about different representations for positive and negative zero. I vaguely recall reading claims that having a negative zero representation is extremely important in ...
0
votes
1answer
137 views

Are there compilers which optimize the use of mathematical functions?

Today while programming I stumbled upon the following question - are there any compilers which optimize based on mathematical assumptions? For instance in cases like unsigned int i,b; (i,b not ...
8
votes
2answers
157 views

Should `Vector<float>.Equals` be reflexive or should it follow IEEE 754 semantics?

When comparing floating point values for equality, there are two different approaches: NaN not being equal to itself, which matches the IEEE 754 specification. NaN being equal to itself, which ...
3
votes
1answer
1k views

Where should I start learning math with regards to programming [duplicate]

I've created several systems already, a web based menu system, a payroll system and I am currently developing a patient administration system, I know java,C,C++ C#, javascript PHP and other ...
1
vote
1answer
45 views

How to handle user created expressions in application

In our application users can enter custom expressions to calculate certain things. For instance they can specify an invoice and define a number of lines for cost calculation. Example for a course ...
2
votes
2answers
80 views

From a set of rules, derive the implications? [closed]

I've only just become interested in this domain, so sorry if I'm not using the correct terminologies. What I want is the following: Say I have a set of rules (or constraints), I want to derive some ...
5
votes
2answers
306 views

Bin sorting problem - Please help categorize

I have a problem I am developing a solution for and currently I solve it with a brute force solution that checks all possibilities. It works for small numbers of bins but I'd like to work with a ...
2
votes
0answers
79 views

Program to select N integers with constraints [closed]

I need to write a program which takes 4 inputs as follows N = The number of integers to be generated (10 < N < 10000) Start = The minimum value of the integers (100 < Start) End = The ...
2
votes
1answer
620 views

Number of parallel lines in a given set of lines [closed]

I am given N lines, i.e, I am given a,b,c for N lines. And each line is of the form ax + by + c = 0. I need to find out the maximum number of lines that are parallel to each other. For this, first I ...
3
votes
3answers
720 views

Why is the “period of a (pseudo)random number generator” important?

I've been trying to understand (pseudo)random number generator code from various sources and the concept of the period continues to elude me. To satisfy the minimum level of understanding, I've tried ...
4
votes
2answers
94 views

Should a generic vector class allow non-finite doubles as values?

I am currently writing an immutable multipurpose vector class in Java that essentially wraps a double[]. The class will be part of a game library, used to calculate entity positions, physics, pixel ...
17
votes
1answer
2k views

Why does Math.min work with a one element array

According to MDN Math.min accepts only numbers, and if one of the arguments is not a number, it'll return NaN. It's true that if we pass an array with multiple numbers we get NaN, like this: ...
24
votes
11answers
5k views

Why do we still use floats? [duplicate]

I understand why floats served a purpose in the past. And I think I can see why they're useful in some simulation examples today. But I think those example are more exceptional than common. So I ...
12
votes
3answers
5k views

Handling extremely large numbers in a language which can't?

I'm trying to think about how I would go about doing calculations on extremely large numbers (to infinitum - intergers no floats) if the language construct is incapable of handling numbers larger than ...
29
votes
10answers
7k views

Why is Math.Sqrt() a static function?

In a discussion about static and instance methods, I always think, that Sqrt() should be a instance method of number types instead of a static method. Why is that? It obviously works on a value. // ...
3
votes
2answers
154 views

C# Abstract math classes from libraries

I'm currently writing a library that abstracts 3D rendering and uses SharpDX and OpenTK as graphics libraries. The problem is that OpenTK and SharpDX have their own implementations of Vector2, Matrix, ...
2
votes
2answers
214 views

What are the advantages of matrix multiplication over individual variables (graphics)?

I am learning OpenGL and the tutorials (1, 2) I'm reading teach me that to scale/rotate/translate an object you have to know matrix multiplication. Why? Instead of 3x3 matrix you can use 6 floats: ...
2
votes
3answers
189 views

How does google calculate travel distance/time

I've been working for quite a while now on a service that generates optimal routes for a given set of addresses and vehicles (Vehicle routing problem / traveling salesman problem). Now it's all ...
4
votes
1answer
552 views

Transpose a matrix without a buffering one

How is it possible to transpose a MxN matrix without using a "buffering" matrix? In the latter case it's easy and quite the "classic" approach... Given a matrix[M][N], I would like to put it into a ...
3
votes
1answer
918 views

What will generate an adjacency matrix file with a specified topology for me?

I am writing an application that takes some file specifying an adjacency matrix and uses this to construct a graph (in this case, a directed social network). What I would like to do is specify the ...
2
votes
4answers
216 views

What is the best data model to represent mathematical range (in database, xml, json…)?

For example, greater or equal to 50 and smaller than 100 (>=50 && < 100) smaller than 10 or greater than 40 (<10 || >40) I have been thinking about how to represent ...
-2
votes
1answer
77 views

Computer Algorithms for Polynomial Regression [closed]

Given a data set of arbitrary size, what algorithm would be appropriate for performing the polynomial regression on the data set such that the highest degree of the polynomial is n? If there are ...
20
votes
11answers
1k views

How is fundamental mathematics efficiently evaluated by programming languages?

As I get more and more involved with the theory behind programming, I find myself fascinated and dumbfounded by seemingly simple things.. I realize that my understanding of the majority of fundamental ...
17
votes
1answer
9k views

Treating a 1D data structure as 2D grid

I am working with a native class that represents a 2D image as a 1D array. If you want to change one pixel, for example, you need to now how to derive the index from the x,y coordinates. So, let's ...
3
votes
1answer
205 views

why adding a vertex in a graph represented using an adjacency matrix takes O(|v|^2) time complexity?

Adding a vertex in a graph that is represented using an adjacency matrix takes O(|v|^2) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency matrix > add vertex). But ...
1
vote
1answer
59 views

How an add vertex operation could be performed in constant time for a graph represented using adjacency list?

Adding a vertex in a graph that is represented using an adjacency list takes O(1) time complexity according to http://bigocheatsheet.com/ (graph operation > adjacency list > add vertex). It is said ...
1
vote
4answers
598 views

What is the “correct” way to store functions in a database?

Note: Yes, I know that storing functions in databases should be punishable by law. We are developing a financial web application using PostgreSQL, Sinatra and AngularJS. As you may have guessed, a ...
16
votes
1answer
598 views

In what programming language did the use of the percent sign (%) to mean modulo/remainder originate?

In what programming language did the use of the percent sign (%) to mean modulo/remainder originate? This previous post1 explains that the symbol % was likely chosen because it includes a slash, ...
4
votes
1answer
254 views

Why does Java define BigInteger / BigDecimal values of 10?

Question perhaps slightly left of field - but I'm curious as to the logic behind why Java's BigInteger/BigDecimal classes feel the need to define a constant of TEN? Example taken from ...
3
votes
0answers
379 views

Fast fixed-size (256 bit) integer modulo/division

What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful. It seems ...
3
votes
4answers
5k views

TEA algorithm constant 0x9e3779b9 said to be derived from golden ratio, but the golden number is 1.618?

I'm trying to understand a constant 0x9e3779b9. What kind of data is this? It's not binary, not decimal, what is this? It's a constant used on the TEA algorithm. It says it's derived from the golden ...
0
votes
1answer
42 views

Error handling in math library functions

When writing a library function, such as double getAvg(double[]); how should one handle the empty array? (Note that, mathematically speaking the avg of an empty set is undefined.)
3
votes
1answer
217 views

When writing a math library, will operator overloading maintain OOP?

I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just ...
6
votes
5answers
306 views

Hamming Distance using a dictionary

First time poster. I'm currently programming a hamming distance program using a dictionary. So if we start with the word "cat" and we want to transform it into "dog", the sequence is ...