Tagged Questions
2
votes
3answers
155 views
Is there any way to make my project Euler#14 solution faster?
I'm solving project euler problems and uploading my solutions to github.
Some of my solutions are just based on math and are thanks to that very fast, but #14 is way too slow, and I have no idea how ...
3
votes
1answer
125 views
Project Euler 407: Is there any more optimal way to solve this idempotent equation (modulo n ring)?
Project Euler problem 407:
If we calculate a2 mod 6 for 0 ≤ a ≤ 5 we get: 0, 1, 4, 3, 4, 1.
The largest value of a such that a2 mod 6 = a is 4.
Let's call M(n) the largest value of a < n ...
6
votes
2answers
344 views
Speed up solution to Project Euler problem 75
I've been programming for a few months now, and have used Stack Overflow a great deal, but this is my first post. Anyway, I wrote this code for Project Euler problem 75, and was curious if anyone knew ...
7
votes
1answer
230 views
Project Euler #3 - how inefficient is my code?
So I am essentially a complete newbie to programming, and have been attempting to learn Python by completing the Project Euler problems. I haven't gotten very far, and this is my code for problem #3 :
...
2
votes
3answers
121 views
Project Euler - Shortening Problem 2
You might have read my question on shortening my code to a one-liner for Problem 1. So, I was wondering, is there any more tricks of the trade to shorten my Problem 2 solution:
fib = [0, 1]
final = 1
...
3
votes
1answer
110 views
Project Euler Problem 1
This is my python solution to the first problem on Project Euler:
n = 1
rn = 0
while n < 1000:
if n%3 == 0 or n%5 == 0:
rn += n
n = n + 1
print(rn)
I would like to find a way to ...
0
votes
3answers
117 views
How can this python code be improved?
I'm trying to become more proficient in Python and have decided to run through the Project Euler problems.
In any case, the problem that I'm on (17) wants me to count all the letters in the English ...
2
votes
1answer
59 views
Can this small snippet of code be better written? It organizes a long string into a list of lists
This code loads the data for Project Euler problem 18, but I feel that there must be a better way of writing it. Maybe with a double list comprehension, but I couldn't figure out how I might do that. ...
2
votes
1answer
76 views
Largest Prime Factor
I'm trying to learn Python by working my way through problems on the Project Euler website. I managed to solve problem #3, which is
What is the largest prime factor of the number 600851475143 ?
...
4
votes
2answers
260 views
Any better way to solve Project Euler problem # 5
So, here's my attempt on Problem # 5 of Project Euler, which is looking quite clumpsy when seen first time. Is there any better way to solve this? Or any built-in library that already does some part ...
0
votes
2answers
163 views
optimizing project euler #83 solution
I have solved the project euler problem 83 using uniform cost search. This solution takes about 0.6s to solve. I want to know if anyone can get the code to run relatively faster without changing the ...
2
votes
2answers
299 views
Python Code Review - Project Euler #12
I just figured out Project Euler problem #12. This the first one I've done in Python, so I'm putting my code out there to hopefully get some constructive criticism.
If anyone is interested, would ...
8
votes
1answer
276 views
Help me make my Python code clearer
Here's my solution to Project Euler problem 40.
import operator
import math
def levels(n):
return 9 * n * 10 ** (n - 1)
def face_value(i):
def level_filler(i):
n = 1
yield 1
...
5
votes
3answers
423 views
Optimizing Code for Project Euler Problem 14
For Project Euler problem 14 I wrote code that runs for longer than a minute to give the answer. After I studied about memoization, I wrote this code which runs for nearly 10 seconds on Cpython and ...
4
votes
2answers
479 views
Project Euler problem 11 in python
My solution for project euler #11 in python. Possibly it can be improved. But other than improvements, I have 2 extra questions, more likely confessions, mostly because of my laziness:
1- Would it be ...
3
votes
2answers
198 views
A little scheme programming challenge
I am learning scheme to get something new from a programming language and this code below is the solution to Project Euler question 21 but the code runs 10x slower than the listed Python code when I ...
2
votes
1answer
221 views
Isn't this dynamic programming?
I was solving problem 18 and 67 on Project Euler and came up with an algorithm that actually goes through almost all the possibilities to find the answer in O(n) time. However, ProjecEuler claims ...
0
votes
2answers
111 views
How do I add memoization to this problem? [closed]
Problem
Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
How many routes are there through a 2020 grid?
Solution
Here is my ...
4
votes
2answers
235 views
Improving runtime of prime generation
I just answered the question on project euler about finding circular primes below 1 million using python. My solution is below. I was able to reduce the running time of the solution from 9 seconds to ...
3
votes
2answers
156 views
Python vs. Java Runtime on Euler 22
On performing the following Euler problem, Python takes up less lines and runs faster (Python ~0.05s, Java ~0.3s on my machine).
Could I optimize this Java code in any way? The problem is here
...
2
votes
2answers
1k views
Python Solution for Project Euler #2 (Fibonacci Sums)
I'm a fairly new programmer (just started yesterday!). I decided to tackle Project Euler #2 today, as I did #1 yesterday without many problems. I came up with what seems to me to be a working ...
4
votes
2answers
281 views
Euler 35 - python solution taking too long
Here is my solution for Project Euler 35. (Find the number of circular primes below 1,000,000. Circular meaning all rotations of the digits are prime, i.e. 197, 719, 971.) The code takes about 30 ...
2
votes
2answers
261 views
Project Euler, #4: Incorrect Results on 7-digit numbers
I've got my answer working (up until a 7-digit answer is requested, anyway), and would like some help
returning the correct answer
speeding up the results
I was thinking of storing the values of ...
1
vote
5answers
898 views
Sieve of Eratosthenes: making it quicker
I was thinking about doing problem 23 of Project Euler. It includes the difficulty where you have to factorize primes. I had already done that in problems I solved earlier, but it was only necessary ...
26
votes
10answers
2k views
Little python script: Use separate functions?
I started programming with Java and C++, so I'm used to having a 'main' function that calls other functions that do the actual work. At university I was always told that doing actual computation in ...
21
votes
7answers
2k views
Project Euler problem 1 in python
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 isMultiple ...