All Questions
260 questions
2
votes
0
answers
74
views
backward induction algorithm computation
Is there a way to significantly speed-up this code?
I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
2
votes
0
answers
134
views
How to make this arbitrary precision π calculator using Machin-like formula run faster?
Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π.
I used Machin-like formula to calculate π, in homage of William Shanks, who calculated ...
3
votes
3
answers
598
views
Binary Insert Method - handling edge cases
I've created a function that uses binary search to insert an element into an array (similar to this question). I haven't benchmarked it, but based on my knowledge it should get \$O(1)\$ in the best ...
3
votes
3
answers
16k
views
Finding consecutive occurrences of a value in an array
Given an array, return True if the array contains consecutive occurrences of a specified value:
...
-1
votes
1
answer
176
views
Using pandas .apply to while loop through every row of the dataframe to get to intended substring given starting and ending index of a string [closed]
I have a function called postprocess that applies while loop condition to find for - and ...
5
votes
1
answer
142
views
Naive Solver of Matrix with Periodic Boundary Conditions Feedback
I am creating an \$O(n)\$ solver for an \$Ax = b\$ system where \$A\$ has the form
\$
A = \begin{pmatrix}
a_1 & b_1 &&&d_{u}\\ c_1 & a_2 & b_2\\& \ddots & \ddots &...
6
votes
1
answer
495
views
Python knapsack program
I have this data for the knapsack problem:
List of product prices = MENU
Most popular product count = MOST_POPULAR_COCKTAIL
...
3
votes
1
answer
89
views
Check which sinks are connected in the pipe system using Python
It would be very helpful to me as a beginner if I could get feedback on my code, specifically about the efficiency of algorithm used and potential improvements in code quality.
Code context:
There is ...
4
votes
1
answer
140
views
Efficient polynomial multiplication in Python
I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
9
votes
6
answers
4k
views
Goldbach’s Conjecture in Python
Input Format
Input starts with an integer n (1 ≤ n ≤ 100) indicating the number of cases. The following n lines each contain a test case of a single even number x (4 ≤ x ≤ 32000).
Output Format
For ...
6
votes
1
answer
347
views
Codeforces: D2. Counting Is Fun (Hard Version)
The code works okay for the following problem.
Problem
An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
8
votes
3
answers
294
views
Refactor the code which performs "cross-product", "reduce", "product of list" and "sum of list"
I have come up with a sequence of steps to find the maximum product of y positive numbers which add up to x. But the program is ...
4
votes
4
answers
1k
views
Creating an O(n) algorithm for an array of integers
To avoid plagiarism in my university, I am going to modify the problem.
Henry likes to jump from building to building. The heights of each building are given as a list of H numbers. We also number ...
4
votes
1
answer
564
views
Prime factorization algorithm by using the multiprocessing module of Python
I may introduce a Python code of prime factorization which is from my personal project that I'm working on.
...
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 ...