Skip to main content

All 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 ...
Robert S Ciaccio's user avatar
2 votes
1 answer
2k views

Fast Prime Sieve (Python Implementation)

A modified version of the prime sieve. I actually doubt it could be implemented any faster, but I might be wrong: ...
Tobi Alafin's user avatar
  • 1,792
3 votes
1 answer
219 views

Stable reversed Tartaglia's triangles

Inspired by Minimising the triangle I am writing a fully tested program to solve the following problem: A triangle needs a good foundation. Every row in the triangle is derived from the sum of the ...
Caridorc's user avatar
  • 27.9k
2 votes
1 answer
2k views

Extract data from large JSON and find frequency of contiguous sub lists

I have been writing some code (see component parts here and here) that: Takes a very large JSON (15GB gzipped, ~10million records) Extracts the relevant parts of the JSON into a list of lists Creates ...
ADatoo's user avatar
  • 85
2 votes
3 answers
404 views

Most effective search algorithm for guessing list of strings via function returning bool if substring is in list using Python

I trying to figure out the most effective way to accomplish this task: A function, check(), contains a list of strings. Calling the function with a string as ...
n0k's user avatar
  • 21
5 votes
1 answer
242 views

Calculating the energy of the harmonic oscillator using a Monte Carlo method

The problem The partition function for the quantum harmonic oscillator can be written in the path integral formulation as $$Z\propto\int Dx(\tau)\exp\left(-\frac{S_E}{\hbar}\right)=\int Dx(\tau)\exp\...
My Code is a Flying Circus's user avatar
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 ...
Alex's user avatar
  • 464
10 votes
2 answers
513 views

Naive implementation of KMP algorithm

After reading this answer to the question "High execution time to count overlapping substrings", I decided to implement the suggested Knuth-Morris-Pratt (KMP) algorithm. I used the pseudo-code listed ...
Graipher's user avatar
  • 41.3k
9 votes
1 answer
9k views

Find the nearest point of a given set of points

Suppose there are a set of given points (represented by x and y two dimensional coordinates), and for any given point A, I want ...
Lin Ma's user avatar
  • 3,493
9 votes
2 answers
2k views

Hash table solution to twoSum

I try the most to solve a twoSum problem in leetcode Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input ...
Alice's user avatar
  • 595
8 votes
1 answer
3k 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 ...
Ilia Sucholutsky's user avatar
7 votes
2 answers
6k views

Sherlock and The Beast

I have recently written the program for the Sherlock and The Beast' HackerRank challenge. That's working fine, but the problem is that it takes too much time if a big number is given as a input. I ...
Mohammad Areeb Siddiqui's user avatar
6 votes
3 answers
821 views

Python script to split overlapping ranges, version 4

This is the fourth iteration of a Python script I wrote that splits overlapping ranges, and this is the fastest version I have wrote so far, and also a version that works for all inputs. I have done ...
Ξένη Γήινος's user avatar
5 votes
1 answer
5k views

Find if one list is a subsequence of another

So the problem of verifying if a list is a subsequence of another came up in a discussion, and I wrote code that seems to work (I haven't rigorously tested it). IsSubequence.py ...
Tobi Alafin's user avatar
  • 1,792
5 votes
1 answer
7k views

Finding missing items in an int list

Here is a problem I am trying to solve: trying to find missing photographs from a sequence of filenames. The problem boils down to: given an unsorted list of integers, return a sorted list of missing ...
Hai Vu's user avatar
  • 730

15 30 50 per page