Given an image matrix, I want to find the pixel points coordinates of all points/pixels in the border of a given circle with center (x,y), where x and y are integers and radius r, where r is also an integer. Considering the border is 1 pixel thick. Ony this outer edge is what I need to find. I’m having trouble
Tag: algorithm
Find the indices where a sorted list of integer changes
Assuming a sorted list of integers as below: I want to find the indices where the values changes, i.e. One approach is to use itertools.groupby: Output This approach is O(n). Another possible approach is to use bisect.bisect_left: Output This approach is O(k*log n) where k is the number of distinct elements. A variant of this approach is to use an
How to generate more than one list from a list, using python functions
I am trying to make a 8 puzzle problem solver using different algorithms, such as BFS,DFS, A* etc. using python. For those who are not familiar with the problem, 8 puzzle problem is a game consisting of 3 rows and 3 columns. You can move the empty tile only horizontally or vertically, 0 represents the empty tile. It looks like
What is Big O in this example of code, O(N) or O(N^2)?
Can you please explain what is Big O in this example of code? Answer It depends entirely on your definition of n. If you define n to be the number of cells in the 2d matrix, then this nested loop is of linear complexity O(n) in relation to it. On the other hand, if you define n to be the
How do you write a loop to merge 2 elements every N number of elements in a list?
I first took this data in a text file below: And I changed it into a list like this: I then removed everything with a colon. And my next step in the program below is to manually merge ‘second’ and ‘text’ and then ‘sec’ and ‘text’. This wont work in a program with an undetermined number of data in the
Appending item on same index
I have these indexes: [3,1,1,2] which shows position for every element in the first list And I need to append these items to that corresponding indexes: to list, to be like in this particular order, so after the item is inserted on the index and the next item is again pointing to the same position, the first added moves to
Palindrome question use of lambda and key
Hey guys so I was working on this problem on the algoExpert platform, but I am struggling to understand what longest and currentLongest are really doing. Just from the beginning, I am not entirely sure what the currentLongest = [0, 1] is doing, is it just saying that it will have 2 values? Are odd and even returning an array
Finding MACD Divergence
I want to create a loop to automate finding MACD divergence with specific scenario/criterion, but I am finding it difficult to execute although its very easy to spot when looking at chart by eyes. Note: you can easily get this as ready available scanner but i want to improve my python knowledge, hope someone will be able to help me
Can this algorithm be called insertion sort or is it some other algorithm?
I was curious that can this way of sorting be called insertion sort, there are a few differences between my code and the original implementation. In insertion sort, we pick the keys from the virtually ‘unsorted’ sub-array and compare it to the left subarray that is sorted. My code doesn’t do that it selects the key from the left subarray
Most efficient way to determine lowest valid number within a big range by only knowing whether your guess is too low
Let’s assume you want to guess a certain number(x) within a big range in Python. A simple external validation function, which you can call as many times as needed, will give you hints: If the number being tested is equal to or higher than the lowest valid number, it will, in both cases, return True (you may not know explicitly