Skip to main content

All Questions

Tagged with
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
2 answers
598 views

Find max in-order difference in array

Given an array A of integers, find the maximum of j - i subjected to the constraint of ...
4 votes
1 answer
338 views

Numerical differentiation on sphere with Python

I have ported from Fortran to Python an algorithm that calculates the numerical derivative along the x direction (longitudinal) of a scalar function s on a ...
4 votes
2 answers
422 views

ECDH implementation in Python (part 3)

After the first and second part, the primary feedback I got was to rename a lot of my variables as I used the same name for different local variables which is really confusing. I tried to hotfix that, ...
4 votes
1 answer
183 views

Shakesort in Python 3

I've done the shakesort algorithm win \$O(n^2)\$, but it doesn't seem that \$O(n^2)\$ is correct because it takes 6-9 steps in the while loop for a list of 4 ...
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 ...
2 votes
2 answers
138 views

Synchronization and backup of directories and files

I'm just learning to write. I set myself a task a few days ago, and today I completed its implementation. The task was to create a "backupper" (I was inspired just by my homework with "...
3 votes
1 answer
604 views

3Sum LeetCode problem coding challenge

LeetCode 3Sum problem: Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the ...
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 ...
2 votes
2 answers
247 views

LeetCode Wildcard Matching with DFS and FSM

I'm trying to solve Wildcard Matching on LeetCode. I found a great solution using the Finite-state machine. The author builds an FSM and searches with BFS. I rewrite the solution with the same idea (...
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: ...
3 votes
2 answers
1k views

Sorting cards by suit and value using Shell Sort

The question description Put a deck of cards in order by suit (in the order spades, heart, clubs, diamonds) and by rank within each suit, with the restriction that the card must be laid out face down ...
8 votes
1 answer
3k views

Python files sync

I'm trying to do a one-way directory sync. Given a list of existing files in a dir, I'd like to make the files in the dir equal a new list of files. There will be subdirs under the dir. Because ...
6 votes
4 answers
483 views

Traversal Heap Sort (No Extractions)

I developed a heap sort variant that sorts a heap through traversal. Unlike in the standard heap sort, the algorithm does not remove the min element from the heap instead it traverses all the nodes of ...
-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 ...

15 30 50 per page
1
2 3 4 5
81