All Questions
Tagged with python-3.xalgorithm
324 questions
27votes
7answers
8kviews
21votes
4answers
44kviews
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 ...
17votes
7answers
4kviews
Stack data structure in Python 3
I have implemented a stack in Python 3, and it works well. If anything needs to be improved, I would appreciate the criticism. ...
17votes
2answers
2kviews
Yandex programming contest: Alarms
I've tried to solve this challenge about 4 hours during the contest, but all my attempts exceeded the time limit. I tried to solve it with min-heap, but can't pass all the tests. How it can be solved ...
15votes
2answers
4kviews
Condorcet voting method in OOP Python
For learning purposes, I made this little class which determines the Condorcet winner of a rank voting election (basically, a Condorcet winner is a candidate that would beat every other candidate in a ...
14votes
1answer
328views
Recover flights from found tickets
I just found a whole bunch of plane tickets that only have a start and destination on them. I also know the route started in a certain city. I would like to recover the (alphabetically) first possible ...
13votes
2answers
1kviews
Mean π: Archimedes vs. Gauss - π computation through generalized means
I've written this simplified code to compute Pi for educational/demonstration purposes. These methods are based upon the generalized means: see a presentation on Pi and the AGM. Archimedes' method ...
13votes
1answer
699views
Bratwurst.py - A helper program for a cashier
I am a student in Germany, more specifically in Bavaria, and here we use to have a so-called "Kirwa", an event for celebrating the establishment of the local church - technically that's the ...
12votes
3answers
5kviews
Python π = 1 + (1/2) + (1/3) + (1/4) - (1/5) + (1/6) + (1/7) + (1/8) + (1/9) - (1/10) ...1748 Euler
I wrote this code to show that my reddit post is correct. After the first two terms, the signs are determined as follows: If the denominator is a prime of the form 4m − 1, the sign is positive; if ...
12votes
2answers
2kviews
Tower of Hanoi Recursive Implementation using Python with OOP
I have just finished a small program for Tower of Hanoi using recursion. I did it to practice OOP which I recently learnt. It took me about 2 hours to research about the recursive algorithm and write ...
12votes
2answers
8kviews
Simple 2048 AI in Python
A few weeks ago, I wrote a Python implementation of 2048. Since then, I've been working on a simple AI to play the game for me. The code uses expectimax search to evaluate each move, and chooses the ...
12votes
1answer
7kviews
2D Bin Packing Algorithm Implementation
I wrote a 2D greedy bin packing algorithm using Python 3.6 Heres a quick summary: The algorithm consists of two classes (which I will attach at the end of this file along with a link to my github repo)...
11votes
2answers
5kviews
Invert a dictionary to a dictionary of lists
I have a dictionary whose keys are related to list of values, but any value may be related to many keys, hence be contained in various lists-attached-keys. To highlight such relation; I build (in ...
11votes
3answers
7kviews
Python implementation of the Ramer-Douglas-Peucker Algorithm
I recently implemented the RDP polygon approximation algorithm in Python and I'm skeptical of whether or not I implemented it correctly of with the greatest efficiency. The algorithm runs in around 0....
11votes
1answer
2kviews
"Mixing Proteins" HackerRank challenge
I am doing this problem on HackerRank and I'm failing test cases because it's taking too long to run when n and k get over 8000. I believe the dictionary lookup should be \$O(1)\$ while lists are \$O(...