Skip to main content

All Questions

Tagged with
27 votes
7 answers
8k views

Python program to calculate GCD

...
Delfin Biju's user avatar
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 ...
N3buchadnezzar's user avatar
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 ...
user avatar
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 ...
Linus Rastegar's user avatar
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: ...
Phong's user avatar
  • 263
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 ...
BBSysDyn's user avatar
  • 231
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: ...
nrasic's user avatar
  • 133
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 ...
ChrisC's user avatar
  • 223
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 ...
Latika Agarwal's user avatar
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. ...
Victor C's user avatar
  • 113
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 ...
samrap's user avatar
  • 255
10 votes
2 answers
21k views

Pretty-print Pascal's triangle

...
matheussilvapb's user avatar
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. ...
Phil's user avatar
  • 285
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: ...
Juicy's user avatar
  • 481
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: ...
Chezhiiyan Sabapathy's user avatar

15 30 50 per page
1
2 3 4 5
14