All Questions
Tagged with mathematics python
202
questions
27
votes
7
answers
8k
views
26
votes
4
answers
1k
views
Generalized Project Euler 1: A sledgehammer to crack a nut
The problem
Project Euler 1 is one of the most asked questions on site. However I wanted to solve the more general problem of division.
Multiples of a list
If we list all the natural numbers ...
21
votes
4
answers
44k
views
RSA algorithm implementation in Python 3
First, a reminder of the RSA algorithm and what my program implements:
Take two distinct, large primes p and q
Ideally these ...
16
votes
1
answer
782
views
Large Number Limit Extravaganza
I am writing a program that computes
$$n-n \cdot \left(\prod_{i=1}^n (1-\frac{1}{p_i})\right)$$
which is rewritten in my code as:
$$\left(1-\left(\prod_{i=1}^n(1-\frac{1}{p_i})\right)\right) \cdot ...
14
votes
3
answers
8k
views
Tonelli-Shanks algorithm implementation of prime modular square root
I did an implementation of the Tonelli-Shanks algorithm as defined on Wikipedia. I put it here for review and sharing purpose.
Legendre Symbol implementation:
...
13
votes
2
answers
1k
views
Numerics for a game theory calculation using expected utility
I am trying to replicate Bruce B. de Mesquita's (BDM) results on political game theory for prediction. Based on where actors stand on issues, their capabilities, salience, BDM's method attempts to ...
13
votes
1
answer
1k
views
Temperature Interpolation
I want to interpolate temperature in correlation with height. I have temperature data from stations with coordinates and height in this format:
...
12
votes
2
answers
36k
views
Calculating Exponential Moving Average in Python
I'm in the process of creating a forex trading algorithm and wanted to try my shot at calculating EMA (Exponential Moving Averages). My results appear to be correct (compared to the calculations I did ...
11
votes
7
answers
11k
views
Check if a given number N is a power of k
I am trying to solve a problem to check whether a given number N is a power of k.
Example:
Input 9, 3 > True // 3**2 = 9
Input 10, 2 > False
Input 4096, 16 > True // 16**3 = 4096
I want to know ...
11
votes
3
answers
4k
views
Determining Pythagorean triples based on the hypotenuse
Below is my written code to determine if, based on the hypotenuse, a Pythagorean triple is possible, and what are the lengths. I was wondering if there is a more efficient way of doing so.
...
11
votes
1
answer
5k
views
Factoring quadratic equation
I have a program I am writing that calculates Algebra 2 functions and equations. The interface is all CLI, and I even made commands that are similar to shell commands. That's not the part I want ...
10
votes
2
answers
21k
views
10
votes
2
answers
1k
views
Find highly composite number using Python 3
A highly composite number (HCN) is a positive integer with more divisors than any smaller positive integer ha according to Wikipedia. Here is a YouTube video about it.
...
10
votes
1
answer
2k
views
Modular Exponentiation
I want to solve the following for \$x\$ (in Python):
\$x^{101} = 8765 \ (\mod{9691573})\$
I coded this:
...
9
votes
5
answers
5k
views
Efficiently find all the Pythagorean triplets where all numbers less than 1000
How can I make this code run faster:
...