With the following data, I think I want a column (DESIRED_DURATION_COL) to work out the duration (according to start_datetime) of consecutive Truths: project_id start_datetime diag_local_code DESIRED_DURATION_COL 1 2017-01-18 False 0 1 2019-04-14 True 0 1 2019-04-17 True 3 1 2019-04-19 False 0 1 2019-04-23 True 0 1 2019-04-25 True 2 1 2019-04-30 True 7 1 2019-05-21 False 0 This is
Tag: algorithm
Reversing lists partially by reversing does not update the list
I am trying to work through the following problem: I am trying to solve this problem by reversing the list, then reversing the first k elements of the list and then reversing the remainder of the list. Like this: But this is my output. The list nums stays the same: Despite the fact that nums is the correct order in
Algorithm for ordering data so that neighbor elements are as identical as possible
I have a (potentially large) list data of 3-tuples of small non-negative integers, like I want to order the tuples within data so that neighboring tuples (data[i] and data[i+1]) are “as similar as possible”. Define the dissimilarity of two 3-tuples as the number of elements which are unequal between them. E.g. (0, 1, 2) vs. (0, 1, 2): Dissimilarity 0.
Trouble sorting list of lists in Python with Insertion Sort
I am currently making a Python program which takes in the name of a grocery item, the aisle it’s on, its location along the aisle, and the price. It holds the data in a list of lists, with each inner list containing 4 elements. The program attempts to create the optimal route through the aisles, with traversal on odd aisles
Optimizing permutation generator where total of each permutation totals to same value
I’m wanting to create a list of permutations or cartesian products (not sure which one applies here) where the sum of values in each permutation totals to a provided value. There should be three parameters required for the function. Sample Size: The number of items in each permutation Desired Sum: The total that each permutation should add up to Set
Path through specific vertices without an end point
I am trying to write an algorithm solving a type of maze. It could look something like this: The player character is the red circle and the goal is to collect all the blue squares. The player can move up, down, left or right but only stops when hitting a wall. I start by converting the maze into a graph(going
What is the complexity of str() function in Python3?
I have to create a function respecting an O(n) complexity and to do that i want to use the str() function. Can someone explain me if : Is this code O(1) or O(4) because of the 1+0+0+0 ? Answer As can be seen from the source code, the implementation of int.__str__ has runtime complexity of O(m*n) where m is the
Ordering a two-dimensional array relative to the main diagonal
Given a two-dimensional array T of size NxN, filled with various natural numbers (They do not have to be sorted in any way as in the example below.). My task is to write a program that transforms the array in such a way that all elements lying above the main diagonal are larger than each element lying on the diagonal
How can I implement Circular SSTF in this code?
In my Operating Systems class, we have to present one algorithm as our final project. A mock model for any of the OS algorithms. I choose an algorithm which is an improved/variation of regular SSTF algorithm. It is called Circular SSTF. I have already implemented SSTF in python. But I can’t figure out a way to implement Circular SSTF. Any
Is it possible to do a depth first search iteratively without copying visited nodes?
Background I am searching a 2D grid for a word. We can search left/right and up/down. For example, in this grid, searching for “abef” starting at (0,0) will return True Example (grid1): Where I’m at The recursive version gives expected results (see dfs_rec() below). The iterative version also gives expected results (see dfs_iter() below). However, in this version I am