2
votes
2answers
72 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 ...
2
votes
0answers
57 views

Python: How do I optimize the solving of ODEs?

I have been trying to figure out a way to optimize the solving of ODEs in Python but haven't been able to achieve this goal. I tried getting help via a bounty on SO using cython but nothing came of ...
4
votes
1answer
128 views

Optimizing python code for big data sets

I'm trying to optimize a python string that works on big data sets, the way it works is by taking in a with a list of keywords and scores and taking in a file loaded with data from the twitter api. ...
3
votes
1answer
96 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 ...
4
votes
2answers
187 views

How can I memoize or otherwise optimize this code?

The code checks many more conditions like the one below. I was thinking to memoize it, but I can't think about how (writers block). How else could I optimize this? I know it seems silly, but my code ...
1
vote
1answer
38 views

Improve file-path finding method

I am using a recursive algorithm to find all of the file-paths in a given directory: it returns a dictionary like this: {'Tkinter.py': 'C:\Python27\Lib\lib-tk\Tkinter.py', ...}. I am using this in a ...
5
votes
2answers
154 views

Help refactoring my tic tac toe game

I'm very new to coding and have been diving into the skill with Python as my first language. One of the first programs I wrote for a class was this Tic Tac Toe game. I re-wrote this game using classes ...
2
votes
1answer
29 views

Eliminate for loops in numpy implementation

I have the following dataset in numpy indices | real data (X) |targets (y) | | 0 0 | 43.25 665.32 ... |2.4 } 1st block 0 0 | 11.234 |-4.5 } 0 ...
-2
votes
2answers
153 views

Any way to change optimize this or/and change to recursion?

Number can be very big.Script is taking number as a "number" list and crossing from 10-decimal based system to n-based system until list equals "5".I don't use letters like in 16-base ...
2
votes
2answers
207 views

How do I make this program run less unnecessary loops?

I am currently trying to teach myself some programming. I have started to work with Python by doing this challenge. When I test run it works out fine, however when I run this code with longer strings ...
2
votes
1answer
62 views

Iterative Collatz with memoization

I'm trying to write efficient code for calculating the chain-length of each number. For example, 13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1. It took 13 iterations ...
0
votes
1answer
61 views

Progressbar in Python

i wish to improve my Progressbar in Python from __future__ import division import sys import time class Progress(object): def __init__(self, maxval): self._seen = 0.0 self._pct = ...
0
votes
3answers
105 views

How to optimize this simple Python program?

Here is a simple piece of code in Python. It is a solution to the SPOJ's JPESEL problem. Basically the problem was to calculate cross product of 2 vectors modulo 10. If there is a positive remainder, ...
1
vote
1answer
102 views

Hangman in Python

I created this version of Hangman in Python 3, anyone got any tips for optimization or improvement? import random HANGMAN = ( ''' -------+''', ''' + | | | | ...
3
votes
1answer
175 views

Improve efficiency for finding word frequency in text

Premise: Write a program that counts the frequencies of each word in a text, and output each word with its count and line numbers where it appears. We define a word as a contiguous sequence of ...
2
votes
1answer
37 views

How can I speed up this correlation function Python

I am writing a specialized version of the cross correlation function as used in neuroscience. The function below is supposed to take a time series data and ask how many of its values fall in specified ...
0
votes
0answers
34 views

Merge all text files in a directory and save a temp file. Suggestion to improve my code

i coded this function where you read all text file in a directory and you save in a temporary file all values. The text files are x,y, and z format. The function returns the name of the temporary ...
0
votes
1answer
28 views

Python right position for a Error message in a class

first of all sorry for this easy question. I have a class class Grid(object): __slots__= ("xMin","yMax","nx","ny","xDist","yDist","ncell","IDtiles") def ...
2
votes
1answer
46 views

python Improve a function in a elegant way

I have a grid as >>> data = np.zeros((3, 5)) >>> data array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]] i wrote a function in ...
3
votes
1answer
99 views

Python/Django Script - Is it crap? Objects duplicated or passed?

I've written a script using the Django ORM to store 'configuration settings' and interacting with the Google Drive API and another API. The script creates a base project folder and subfolders in ...
3
votes
3answers
162 views

Advice on program which calculates scores for predictions of Football scores

I am writing a program which calculates the scores for participants of a small "Football Score Prediction" game. rules are: if the match result(win/loss/draw) is predicted correctly: 1 point if the ...
1
vote
2answers
94 views

Consolidate list of ranges that overlap in Python

I wanted to implemented an algorithm in Python 2.4 (so the odd construction for the conditional assignment) where given a list of ranges, the function returns another list with all ranges that overlap ...
2
votes
1answer
100 views

How to make BWT inverse faster, and how to understand why the optimizations work?

I think understanding basic data compression and pattern finding / entropy reduction primitives is really important. Mostly the basic algorithms (before the many tweaks and optimizations are made) are ...
3
votes
2answers
467 views

How can I improve the performance of this code?

I was solving the Find the Min problem on facebook hackercup. The code below works fine for the sample inputs given there, but for input size as big as 10^9 this takes hours to return the solution. ...
2
votes
3answers
122 views

Python function speedup/optimization

everybody...I am working on a p2p streaming sim (which I think is correct), however I've discovered a huge bottleneck in my code: During the run of my sim, the function I include below gets called ...
4
votes
1answer
217 views

Meeting Point problem from interviewstreet.com

I am trying to solve the "Meeting Point" problem from interviewstreet.com: There is an infinite integer grid at which N people have their houses on. They decide to unite at a common meeting place, ...
3
votes
3answers
130 views

How can I clean up this python code?

I am very new to programming and this is my first functional code. It works fine but I'm sure that I could use a lot of optimization. If you see any blunders or would be able to help condense the ...
3
votes
3answers
117 views

Naive prime finder, unexpected behavior in Python

I have verified that both of my following functions successfully find prime numbers. I was pretty sure the function called is_prime_new would be faster than is_prime_old; however, after benchmarking ...
4
votes
3answers
145 views

Optimizing Divisor Sieve

Update: The optimizations so far have been excellent. And I've used Python 64 bit to get around the memory issue, but I came to the problem that 50,000,000+ causes my computer to use up more than it's ...
4
votes
1answer
138 views

Optimizing Python / Numpy Code

So I'm implementing a version of the mean shift image processing algorithm for color segmentation in python/numpy. I've written a pure numpy version of the actual mean shifting per pixel (which I ...

1 2 3
15 30 50 per page