Skip to main content

All Questions

27 votes
7 answers
8k views

Python program to calculate GCD

...
Delfin Biju'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
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
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
9 votes
3 answers
3k views

Save the Prisoner

A jail has prisoners, and each prisoner has a unique id number, S, ranging from 1 to N. There are M sweets that must be distributed to the prisoners. The jailer decides the fairest way to do this is ...
user avatar
8 votes
4 answers
8k views

Pi-calculating program

I saw this question and answer about calculating pi on Stack Overflow, and I decided to write my own program for calculating pi. I used Python and only integers (I didn't want to use floating point ...
Uri's user avatar
  • 181
7 votes
4 answers
28k views

Algorithm to get an arbitrary perpendicular vector

Is there a more efficient/direct way to find an arbitrary perpendicular vector of another vector? ...
Niklas R's user avatar
  • 223
7 votes
2 answers
3k views

Magic Square (Python)

Problem Write a method to return a boolean if an input grid is magic square. A magic square is a \$NxN\$ square grid (where N is the number of cells on each side) filled with distinct positive ...
Emma's user avatar
  • 3,592
6 votes
3 answers
1k views

Implementation of Euler-Maruyama numerical solver

I am trying to write a python implementation of Euler-Maruyama and Milstein schemes for numerically solving stochastic differential equations. The pseudo-code for the algorithms is in the Wikipedia ...
Quasar's user avatar
  • 549
6 votes
1 answer
2k views

Scan-line algorithm to fill in a triangle

I wrote the following script to fill a Triangle. ...
Apple_Banana's user avatar
5 votes
3 answers
2k views

Find smallest number of squares that sum to a number

Leetcode problem 279 “Perfect Squares” is: Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) I wrote the following solution: ...
loremIpsum1771's user avatar
5 votes
2 answers
2k views

Sum of successive powers of digits

Some numbers have funny properties. For example: $$\eqalign{89 &→ 8^1 + 9^2 &= 89 &= 89 × 1 \\ 695 &→ 6^2 + 9^3 + 5^4 &= 1390 &= 695 × 2 \\ 46288 &→ 4^3 + 6^4 + 2^5 + 8^6 +...
Siddarth's user avatar
  • 363
5 votes
2 answers
1k views

Magic Square with Five Methods (Python)

Problem Write a program to return a boolean if an input grid is magic square. A magic square of order \$N\$ is an arrangement of \$N^2\$ distinct integers in a square such that the \$N\$ numbers in ...
Emma's user avatar
  • 3,592
5 votes
1 answer
1k views

Speed up lights-out variant solver in pure Python

I'm doing some challenges to learn new and interesting concepts, this one is about a Lights out variant, instead of toggling only the adjacent tiles, it toggles the whole row and col. It must be ...
Sven's user avatar
  • 209
5 votes
1 answer
217 views

Algorithm Optimization -- Automatic Dimensionality of PCA

I have implemented (rather, edited the implementation of) a technique to automatically detect the optimal number of dimensions for PCA, based off of this paper. This was inspired by ...
artemis's user avatar
  • 193

15 30 50 per page