All Questions
260 questions
59
votes
9
answers
14k
views
Project Euler problem 1 in Python - Multiples of 3 and 5
I'd like suggestions for optimizing this brute force solution to problem 1. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to ...
17
votes
3
answers
5k
views
Knapsack branch and bound: forward filter
I've coded branch and bound to solve the knapsack problem, and use a greedy linear relaxation to find an upper bound on a node I'm currently exploring. What I mean by this is that I first sort the ...
15
votes
1
answer
13k
views
Rotating greyscale images
For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any rotate() function, but doing ...
13
votes
2
answers
1k
views
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 ...
12
votes
3
answers
658
views
Becoming the greatest tower builder
I am trying to learn how to write proper code in python, and stumbled upon the following problem.
Bob is given a set of building blocks b, and a number ...
12
votes
1
answer
1k
views
Sieve of Atkins algorithm
I got the inspiration to write this algorithm from this question. The OP cited the Sieve of Atkin as one of the fastest ways to generate primes. So I figured I would give it a try:
...
11
votes
3
answers
6k
views
Algorithm for competing cells of 0s and 1s
I'm working on a practice algorithm problem, stated as follows:
There are eight houses represented as cells. Each day, the houses compete with adjacent ones. 1 represents an "active" house and 0 ...
11
votes
6
answers
21k
views
12 hours to 24 hours conversion function
I have made a time format converter which converts 12 hour format to 24 hour format. My convert_to_24() takes a string in format of ...
11
votes
5
answers
2k
views
Are the sum of two numbers desired?
Given two input arrays [-1, 8, 3] and [3, 7, 2] your function will return true if any two of the numbers in the first array add ...
11
votes
3
answers
7k
views
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....
11
votes
4
answers
3k
views
n-queens puzzle in Python
I want to increase the efficiency and reduce the time complexity for the n-queen problem in n*n matrix chess. I am able to run only still (11*11) in normal time otherwise for the big number it is ...
11
votes
1
answer
2k
views
Solving Pentomino puzzles by using Knuth's Algorithm X
I wrote a program which solves Pentomino puzzles by using Knuth's Algorithm X. My priorities were: readability, straightforwardness and brevity of the solution, so I didn't try to squeeze as much ...
10
votes
5
answers
1k
views
Finding two consecutive triangular numbers with a given target sum
I need to speed up this code so it can handle inputs in the thousands. It adds triangular numbers to a list based on input n, then it loops through to find if any two consecutive numbers squared in ...
10
votes
9
answers
3k
views
Beginner FizzBuzz in Python
This is my first attempt at solving Fizzbuzz. I've always been pretty weak at algorithms, so I'm trying to improve. Specific feedback on performance would be appreciated.
...
10
votes
3
answers
2k
views
Repeatedly remove a substring quickly
I'm trying to solve the USACO problem Censoring (Bronze), which was the first problem for the 2015 February contest. My solution works for some test cases, but then times out for test cases 7-15. I ...