All Questions
36 questions
27
votes
7
answers
8k
views
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 ...
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:
...
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 ...
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 ...
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 ...
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?
...
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 ...
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 ...
6
votes
1
answer
2k
views
Scan-line algorithm to fill in a triangle
I wrote the following script to fill a Triangle.
...
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:
...
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 +...
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 ...
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 ...
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 ...