I have a grid with cells divided into two regions (pink and blue) by a boundary (grey): The pandas data frame that I have consists of "row" and "columns" of the boundary cells: row col 9 1 9 2 8 3 9 4 8 5 9 5 … 5 14 5 15 Which algorithm can ..

#### Category : algorithm

what are the ways to correctly read the constantly appending file. I make a counter for the line number on which I finished reading the previous time, but every time it takes too long to read the file, how can I process it faster? for line in file: if j >= i: i += 1 ..

I want to find a way in which we can score each tree by summing the scores of its spans and choose the highest scoring binary tree. Assume, I have the following sentence: string = "Revenue was 19.9 million" The spans array represents the scores of span at the corresponding (i, j) position. Here: j=i+1 ..

def selection_sort(li): new_list = [] a = li[0] for x in range(1, len(li)): if li[x] < a: a = li[x] new_list = a print(new_list) b = [1, 2, 5, 3, 7, 4] selection_sort(b) Why does the above code returns empty list. Thank you Source: Python-3x..

import math as m def isprime(a): if a < 2 or a != 2 and a % 2 == 0 or str(a)[-1] == "5" and a != 5 or sum([int(i) for i in list(str(a))]) % 3 == 0 and a != 3: return(False) elif a == 2: return(True) else: for divisor in range(3, m.floor(m.sqrt(a))): if ..

I am trying to split R15.49 to (R, 15.49) or ZAR15.49 to (ZAR, 15.49) I have tried one of the solutions here and implememted the function below: def splitCurrency(string): match = re.search(r'([D]+)([d,]+)’, string) output = (match.group(1), match.group(2).replace(‘,’,”)) return output But I am getting (R, 15) or (ZAR, 15). and its ignoring the digits after the ..

I have a grid with cells divided into two regions, Front and Back by a boundary. Which algorithm can label boundary cell faces (thick line) based on their region? For example labels red faces to "Front" and green faces to "Back". The problem is that the regions (orange and green cells) are not labeled and ..

I am trying to solve an algorithms question that was assigned to me but I can’t figure out a solution in O(n) time complexity. The question is as follows: Given a list of dictionaries containing set of ids, find folders and assignments such that the iteration over the list will produce the sub items of ..

I want to create pairs based on the values of the keys. So lets say I have a dictionary with these values: listing = { ‘A’: [1, 1, 2], ‘B’: [1, 1, 2], ‘C’: [1, 0, 2], ‘D’: [1, 0, 3], ‘E’: [1, 1, 3], ‘F’: [1, 1, 1] } I want to pair the ..

I am trying to find a path between two points in a graph using a depth first search in Python. The idea is to return a path (not necessarily the shortest) from point a to point b or an empty list if a path does not exist. I have a class which contains an adjacency ..

## Recent Comments