Tagged Questions
3
votes
2answers
82 views
Calculating if a point is within a polygon, or outside of it
Here is the function (along with its support functions):
...
4
votes
1answer
67 views
E-commerce product price tracker
I building a very simple price tracker web app. I am using MongoDB with pymongo. The user will enter the URL of the product he wishes to track and the desired amount, when the price goes below this ...
2
votes
1answer
59 views
Typeahead Talent Buddy
Problem is Talent Buddy.
Your task is to
write a function that prints to the standard output (stdout) for each query the user name that matches the query
if there are multiple user names ...
6
votes
1answer
83 views
Russian doll envelops
Interview question from the interwebz
You have a set of envelopes of different widths and heights. One
envelope can fit into another if and only if both the width and height
of one envelope ...
4
votes
2answers
93 views
Typeahead autocomplete functionality challenge
I'm working on a Talent Buddy challenge . In this challenge you have to design the autocomplete functionality of Twitter. You are given a list of queries and possible usernames. You have to return the ...
2
votes
0answers
20 views
Python softmatcher using difflib impracticably slow
I have a softmatch function (below) that takes a donor list and a new entry and looks to see if the given donor already exists. The data is not exact, so I have to use a softmatch to determine ...
3
votes
0answers
47 views
Python Multiprocessing: Using mutable ctype arrays seems to work, yet I am not seeing significant speed-up. Why?
As a brief introduction, I am student working on a body of code which forms part of my Masters' research - this is my first question on SO. My background is in physics and mathematics, so I will ...
1
vote
1answer
33 views
Search a file system for files that match a given pattern
My concerns with this code:
Is there a more efficient way to find files by pattern in Python?
Does os.walk() work in Windows?
Is this code pythonic?
Should ...
4
votes
2answers
139 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 ...
1
vote
2answers
284 views
The efficiency of looping over nested dictionaries in Python
How to make the following code more efficient?
...
3
votes
1answer
162 views
Hackerrank Gem Stones
I am working on some problems on Hackerrank.
John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase Latin letter from 'a' to ...
14
votes
6answers
2k views
Sherlock and The Beast
This is my solution to this question from Hackerrank.
Given N (<= 100000), find the largest N-digit number such that:
The number has only 3 and 5 as its digits.
Number of times 3 ...
4
votes
1answer
50 views
Optimize iteration output to text file
I've written a piece of code which combines given letters in groups of n letters, and writes all the combinations in a text file. This is my first attempt and I wonder if there is an optimal way to do ...
5
votes
1answer
66 views
Calculating “element-wise” the angles between two lists of vectors
Let's say you have two lists of vectors:
v1s = [a, b, c]
v2s = [d, e, f]
I am interested in generating the following ...
0
votes
1answer
49 views
Optimizing this SVG animation for size
I'd like to code review generated svg animation, while this might stretch definition of this site, I really hope this is interesting and revelant topic, as this SVG file is really like any other ...
10
votes
1answer
93 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:
...
3
votes
2answers
82 views
Simplify an if else construct with assignment before if and else
I want to simplify an if: .. else: .. construct:
...
1
vote
1answer
50 views
Getting information from URL efficiently
I wrote a dirty and ugly code to show in console how many bugs are left until the release of elementary codename Isis.
The code works but it's pretty inefficient. What it does is:
downloads the ...
2
votes
1answer
44 views
How can I enhance my jigsaw puzzle solver function?
I'm working on writing code which gets several pieces of an image, and reconstructs them to one whole picture. The images are represented by matrices, and two pieces should be "glued" if the right ...
2
votes
1answer
72 views
How can I optimize my insert function for the cuckoo hash table?
I'm working on class for a hash table where collisions are corrected using cuckoo hashing, I had difficulty writing the insert function, the function is supposed to insert the key if the ...
4
votes
1answer
99 views
Simplifying if else statements in Python code snippet
How can I simplify and optimize this code?
...
4
votes
0answers
93 views
Ways of speeding up this python implementation of SAT (Separating axis theorem)
A project I was working on required the usage of the Separating Axis Theorem to detect collisions between two convex polygons in real time. So I implemented a basic class (...
1
vote
1answer
185 views
Excessive use of lambda with variant of Sieve of Eratosthenes?
This is a function which produces the sum of primes beneath (not including) a certain number (using a variant on the sieve of Eratosthenes).
...
8
votes
1answer
174 views
17
votes
6answers
5k views
Why is my C# program slower than my Python program?
I made a program in Python and wanted it to be faster, so I wrote it on C# because it's compiled. To my surprise, the Python program is much faster. I guess there is something wrong with my C# code, ...
5
votes
4answers
54 views
Number Of Matching Elements In Two Lists
I have many sets of 2 strings. I'm trying to determine the number of matching elements in these 2 strings. The rules are if the strings share a common letter, that's a point, order does matter, but ...
4
votes
1answer
33 views
Refactor Oxford Comma function (and other functions)
I wrote a program that managed projects and created a set of SQL files for each project. In the logic, I have a few functions that, each time I look at them, I wonder if they could be written in a ...
2
votes
3answers
1k views
Retrieving the first occurrence of every unique value from a CSV column
A large .csv file I was given has a large table of flight data. A function I wrote to help parse it iterates over the column of Flight IDs, and then returns a dictionary containing the index and value ...
2
votes
3answers
48 views
Speeding up Project Euler 43 - sub-string divisibility
The number, 1406357289, is a 0 to 9 pandigital number because it is
made up of each of the digits 0 to 9 in some order, but it also has a
rather interesting sub-string divisibility property.
...
5
votes
2answers
321 views
How to optimize for larger files: MemoryError in Python while combining multiple JSON files and outputting as single CSV
I have a number of JSON files to combine and output as a single CSV (to load into R), with each JSON file at about 1.5gb. While doing a trial on 4-5 JSON files at 250MB each, I get the following ...
4
votes
1answer
299 views
Script that scrubs data from a .csv file
Really, what I would like to know is: "What does this script tell you about how I need to improve as a programmer?" I'm somewhat new to both Python and programming, so feel free to minimize your ...
2
votes
1answer
508 views
Collections.Counter in Python3
Can you suggest how I might make the following code more efficient:
...
1
vote
1answer
317 views
Recording timeback seconds of video based on compared pixels from an image
The code reads from the screen, compares a pixel in a previously provided sample image and, if the pixels match, it records timeback seconds of video leading up to it. The output is put into a folder ...
2
votes
0answers
64 views
Optimization Algorithm: Too much memory consumed
What I have here is an implementation of an optimization algorithm called the covariance matrix adaptation evolutionary strategy. I am using this algorithm to optimize the position of wind turbines ...
1
vote
2answers
44 views
How can I optimize this string function so that it could work on very large strings?
I want to build a function which finds the longest substring that is common between two large strings, I want to do this using the first two functions.
I'm running it on very large strings (containing ...
2
votes
1answer
44 views
Project Euler 40: Champernownes's Constant
I just finished Project Euler 40 with a brute force method. As usual, any optimizations would be helpful. (I feel like I'm getting better at this scripting thing)
...
3
votes
2answers
58 views
Optimizing a recursion code over lists
I'm writing three functions which iterate over lists, I want do this recursively, but I think this code is not as efficient as it could be.
...
2
votes
1answer
53 views
Project Euler 39: Integer right triangles
I just finished Project Euler 39:
If p is the perimeter of a right angle triangle with integral length sides, {a, b, c} … For which value of p ≤ 1000, is the number of solutions maximised?
I'm ...
1
vote
1answer
39 views
Project Euler 38: Pandigital Multiples
I just solved Project Euler 38 and was wondering if you guys could provide some suggestions on how to speed it up. I've tried adding extra conditions but they increase the time. Any ideas on how to ...
3
votes
3answers
164 views
2
votes
7answers
2k views
Quadrant Queries challenge
Running the same test 10,000 times with cProfile tells me that most of the damage happens in the count() function. This is my attempt at a solution to the Quadrant Queries challenge from ...
3
votes
1answer
52 views
Truncatable Primes — Project Euler 37?
I just finished Project Euler 37 after a bit of debugging and can't figure out how to make it faster. Whenever I add extra tests that I want to speed the program up, it ends up just slowing it down. ...
3
votes
3answers
251 views
Finding duplicate strings within a file
This code basically finds duplicate strings within a file.
An example: DUPLICATE_LENGTH set to 6, file contains:
...
4
votes
2answers
219 views
Display data based on read configuration file from ssh sessions
I started playing with Python last week. This is a section of code from an application which reads a configuration file and launches ssh sessions and continuously ...
3
votes
1answer
247 views
Statistical samples and distributions
It is usually inefficient to find bugs in a longer code. Unfortunately, after spending too much time in debugging my code, I realize that a good programming habit is important. Please give me some ...
3
votes
3answers
141 views
P2P streaming sim
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've included below gets called about ...
1
vote
3answers
81 views
Optimizing Project Euler 36 - double-base palindromes
This one was quick and simple. Any optimizations?
...
2
votes
1answer
46 views
Project Euler 35 in Python
I'm back with a Python solution for Project Euler 35. Any help would be appreciated; I generate the numbers by observing that all circular primes can only have digits 1, 3, 7, and 9. Then I use the ...
3
votes
2answers
671 views
Hangman in Python
I created this version of Hangman in Python 3. Does anyone have any tips for optimization or improvement?
...
3
votes
2answers
148 views
Generating a random string of characters and symbols
After coding this, I was wondering if there are any ways in which I can improve upon it. It generates a random string of characters and symbols the same length as what is entered by the user. It uses ...