For code that aims to solve problems in all branches of mathematics. (Please do NOT use this tag for incidental trivial use of arithmetic. A simple test to apply is: would an amateur or professional mathematician take an interest in the question?)

learn more… | top users | synonyms (1)

2
votes
0answers
16 views

Symmetry analysis for atom arrangements in a crystal

For a while now I've been meaning to post some of my Haskell code here so that someone can tell me what parts of the language/base library I've been completely overlooking. This is the first thing ...
3
votes
1answer
122 views

Project Euler #549: Divisibility of factorials

This is the problem: Calculate $$\sum_{i=2}^{10^8} s(i)$$ where \$s(n)\$ is the smallest \$m\$ such that \$n\$ divides \$m!\$. Quite mathematical, I've found a better way than brute ...
0
votes
3answers
74 views

Extend number of arguments in std::hypot

I would like to call std::hypot with many arguments (not just 2 or 3). Mandatory requirements: fast run at compile time when possible Non-mandatory ...
0
votes
1answer
56 views

Probability Chance

I'm creating a game and I need some properties to work as percent chance to hit/dodge. I implemented a small testing program that takes percent chance and the amount of hitting attempts as input and ...
0
votes
0answers
30 views

Get vertical acceleration from rotation vector and accelerometer values

My goal here is to calculate the acceleration towards the ground, which I call "vertical acceleration". This seems to be working OK for the most part, except when there is a lot of rotation going on ...
1
vote
2answers
63 views

Calculate difference between two times

I just wrote this script that calculates the time difference between two times. It's going to be used in a larger program that will store the returned value in a database. I'm mainly wondering if ...
-3
votes
1answer
52 views

Printing a prime normalized sequence

The program below generates a prime normalised sequence. So, what happens is this: It asks you to provide a number within a range. Program then calculates a factor which is inverse of product of all ...
2
votes
2answers
67 views

Calculating the sum of the digits in 2^1000

I have a program which calculates the sum of the digits in the number 21000. The program is not beautiful and I was hoping for some advice on how to improve it. The idea I have used is to create an ...
4
votes
2answers
121 views

Calculating pi by adding areas of thin rectangles

I wrote a small program for fun to try to prove Pi by taking a certain precision and radius and using it to calculate the area of the circle. My method should be giving me an area that is just ...
3
votes
0answers
53 views

Computing intersection of 2D infinite lines

I wrote a small program to compute intersection of 2D infinite lines using Boost Geometry A line is defined by two points in Line class. The ...
4
votes
1answer
56 views

Mendelian inheritance

I started out with the Rosalind problems a while back. Turns out it's a great way to learn a new language. I'm still trying to learn Ruby, and while I haven't managed to use regular expressions as ...
3
votes
2answers
82 views

Add item after every nth step

The purpose of the method is to add a list of items after every nth step (5 for example) where the input items are repeated if needed. I'm looking for an overall review and possible how to remove the ...
1
vote
0answers
45 views

Snell's law using Zoeppritz equation by matrices

I have created the following code to calculate Snell's law angles, based on Zoeppritz equations on complex plane. The code works, seems it is returning valid values, but after all the code just looks ...
4
votes
5answers
949 views

Solve 6 simultaneous equations for 8 variables puzzle with Java

I came across this mathematical puzzle, where one really cool answer was a python script to brute force answers. Here's my take, which is essentially a translation of that to Java: ...
1
vote
2answers
49 views

Calculate Kth Row of Pascal's Triangle

Purpose Implement a solution that returns the values in the Nth row of Pascal's Triangle where N >= 0. Math First three rows ...
3
votes
1answer
63 views

Generating a maximal geometric progression of integers

I'm working on a program that generates a maximal geometric progression of at least 3 integers when given a number that the greatest value shouldn't exceed. My current code works, and it's quick(ish) ...
3
votes
2answers
73 views

Implementation of exp function in C using Taylor Series expansion

I am trying to write code to calcultate ex using: $$e^x = \sum_{n=0}^\infty \frac{x^n}{n!} = 1 + x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!} + \cdots $$ This is the code I have, which works ...
3
votes
0answers
50 views

Slow multiplication in a modulo

I am willing to get a linear output of a product in a ring Z/nZ For that I have successfully implemented a code that does a Product in a modulo However, it is not optimized to output the steps ...
-4
votes
2answers
84 views

Find the sum of all numbers below N which divide the sum of the factorial of their digits

\$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible by \$19\$. Find the sum of all numbers below \$N\$ which divide the sum of the factorial of their digits. Note: as ...
1
vote
1answer
130 views

Calculating distance with Euclidean, Manhattan, and Chebyshev in C#

I am by no means proficient at being able to take mathematical concepts and converting them to code. I was wondering if you guys could look at it and make suggestions on how I could fix it or if my ...
0
votes
0answers
49 views

Computing the curvature of a 2D image

I have some MATLAB code that computes the curvature of a 2d image. It computes it iteratively using forward and backward differences. Could you offer some tips for how I can optimize this code? ...
0
votes
2answers
47 views

Pascals probability theory [closed]

After reading about early probability theory I have attempted to write a computational solution to Pascals famous dice problem. The problem was reputedly proposed by one of Pascals friends who ...
3
votes
3answers
115 views

Optimise Division function using divide and conquer, (and multiplication only)

I have the following code I am working on, but I think it can be optimised further probably by improving the min/max variable selection, (see below). The idea is to not use actual division, ('/'), to ...
11
votes
1answer
128 views

Lotto simulator

With the recent craziness of the Powerball in the US, I got interested in building a little lotto simulator to see how frequently I could win with purchasing large amounts of tickets. For those not ...
-5
votes
1answer
76 views

Python to Ruby: inconsistency with float ceil() [closed]

Just for fun, I am trying to convert the following Python from math import * print map(lambda count: ceil( 6 * cos((count + i) * pi / 5) ), range(100)) Which ...
10
votes
3answers
91 views

Reinventing the Math Functions

Just for practice in the mathematical side of programming, I decided to rewrite the math functions, with the addition of the root() function, which the Math library ...
10
votes
2answers
202 views

Project Euler Problem 530: sum of sum of greatest common divisors

Here is a description of Project Euler problem 530: Every divisor \$d\$ of a number \$n\$ has a complementary divisor \$n/d\$. Let \$f(n)\$ be the sum of the greatest common divisor of \$d\$ ...
3
votes
1answer
33 views

Searching the number with the biggest amount of odd divisors in an interval

I wrote this program for school (first year in college) and it works, but it's too slow. I wondered if anyone could help me optimize this a bit, because I've been trying and trying, but it just won't ...
4
votes
1answer
67 views

Count solutions of a equation with a constraint

How to count the solutions of the equation \$x \cdot y + x \cdot z + y \cdot z = n, (0 \leq n \leq 10^4)\$ with the constraint that \$x \geq y \geq z \geq 0\$ ? To solve this i've isolated the z ...
6
votes
2answers
66 views

Bell numbers calculation in C

This is my implementation of the bell() function to calculate the n-th bell number in C. Along with it I made the factorial() ...
1
vote
1answer
71 views

Solving Robot Paths with Pascal's Triangle

I wanted to take on the challenge of the classic Robot Path's problem but solve it using Pascal's triangle. The approach was generate pascal's triangle, then grab the middle element from the row. I ...
4
votes
2answers
503 views

Code Golf Challenge: Calculate Phi (not Pi)

I'm a newbie to C++ (coming from C#) and I decided to complete this Code Golf challenge for fun (though I definitely wouldn't say it's short). Essentially, the challenge was to calculate the ...
8
votes
3answers
338 views

Simple complex number class

This is my first time writing C++, so I would appreciate advice in the areas of: Code style (naming conventions, indentation, etc) Memory usage (am I performing unnecessary object copies?) Class ...
-2
votes
1answer
82 views

Countdown to January 1 2016 [closed]

Already read this, but OP is using some other method. My website finds the time till new year. But this website claims to be accurate to the tenth of a second. So what I found out was my timer and ...
1
vote
0answers
39 views

Find Euler totient of a large range of numbers

(Euler Totient Function) Is there any way to make it faster/better in asymptotic complexity? ...
10
votes
5answers
1k views

Maximum product of 3 integers in an int array

I want to find the maximum product that can be obtained from any 3 integers in an integer array. The optimal solution has time complexity of \$O(n)\$ and space complexity of \$O(1)\$. I managed to ...
3
votes
2answers
54 views

Summations and products and factorials oh my

The proper title of this question should be "Summations and products, and factorials oh my!". After getting quite a bit of useful feedback on this question from @mjolka, and a comment, I decided ...
2
votes
1answer
52 views

Summations and products in F#

I was bored, and looking to do something that involved anonymous functions, and it was suggested by @Quill, that I create a summation function. I decided to also include a product function as well to ...
2
votes
1answer
42 views

Determine the number of factors of a large numbers efficiently

I am trying to determine the number of factors of a large number efficiently. I have written this function but how can it be improved upon? ...
7
votes
4answers
491 views

Next multiple with only 1 and 0 as digit

Problem: Find a multiple of a given decimal number \$N\$ that looks like a binary number. The input will consist of at most \$ 2 \times 10^5 \$ lines, each line consist of an integer \$N\$ (\$0 \lt N ...
7
votes
1answer
163 views

Faster(?) factorial calculations

I saw this question, but was unable to answer because of my inexistant knowledge of Rust, so I decided to try and write an algorithm on my own and put it for review. There is the casual way to ...
3
votes
0answers
108 views

Recursive factorial calculations in Rust

I am trying to calculate very large factorials. I am looking to speed it up as 10000! takes approximately a minute and a half. ...
3
votes
1answer
164 views

Simplifying Radical Expressions

I'm working on a program to handle simplifying square roots (radicals). My biggest issue is, in order to stay precise, I can't have input any longer than 15 digits. Whenever a number is longer than 15 ...
2
votes
2answers
77 views

Project Euler #12 Java implementation

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, ...
4
votes
0answers
39 views

Baby Step Giant Step Discrete Log Solver

I've made a concurrent implementation of the Big Step Giant Step discrete log solver in Go. I'm pretty new to this branch of math, but it seems slow. Any way to speed it up or is this the limit of ...
1
vote
1answer
66 views

Project Euler #11 Java implementation

Project Euler 11 Solution in Java. The problem is at https://projecteuler.net/problem=11 package coderbyte; public class Java { ...
5
votes
1answer
233 views

Rational Polynomial Factoring method

I have written a class containing methods to factor a polynomial equation using the p over q method. The method returns a string that is the factored equation. Here is the class (can also be found ...
4
votes
0answers
49 views

Kernel density regression in Julia

Here is a naive implementation of a kernel density regression algorithm in Julia. The code works, but there is quite a bit of room for improvement though. First, there is not an optimal bandwidth ...
10
votes
3answers
649 views

Simple number theory game

I just started JavaScript about a week ago. For my first project, my goal was to use my knowledge of basic JavaScript to create somewhat of a "thinking computer brain," so to speak. I wasn't focused ...
2
votes
1answer
94 views

Menu driven program to represent polynomials as a data structure using arrays

Write a menu-driven program to represent Polynomials as a data structure using arrays and write functions to add, subtract and multiply two polynomials; multiply a polynomial with a constant, ...