Time limit exceeded in Python, code to check if a number can be reduced to “1”

I am working on this question: You are given a number N. You can perform the following operations on N any number of times: -If N is even, divide N by 2. -If N is odd, replace N with 3N+1. Your task …

How do I write a snakemake input when not all jobs successfully output files from previous rule?

Basically, I have three snakemake rules (other than rule all) and cannot figure this problem out, despite the checkpoint resources. Rule one has my first and only file that I start with. It will have …

Agglomerate adjecent cells and their neighbours of the same type to clusters with python

I’m trying to agglomerate adjacent cells (and their neighbours) that have the same type (integer from 1 to 10) into new clusters by assigning them to a cluster id. As visualised here for some of the …

Python algorithm to approximate closest parallel equivalence of resistors from a list

The formula for series equivalence of resistors: series equivalence = sum(resistors) For parallel it is 1/(sum(1/resistors[i])) I wrote code to return a list of resistors that is closest to a …

N-Queens II using backtracking is slow

The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return the number of distinct solutions to the n-queens …

How can I determine The numerator and the power from a certain number?

8=2^3, 81=3^4. How can I discover or find out which/what number can stand as a numerator and as a power for a certain number for example: 8 is the initial/certain number, but was split to 2 raised to …

Python find the largest square in the matrix dynamic programming

I have a matrix as follows (Python) : matrix = “”” …o..o.o …oo…. …o….o ..o.ooo.. o…o…. .oo…… ..o….o. .oo…… ……… “””…

Python 3: time.perf_counter() output does not match the programme processing time on Coursera

I have been working on a Coursera assignment, it required my run time to be less than 5.00 . The code is below, but my question is basically about the first and last line, where I was testing the …

Finding elements unique to each rows in a 2D array

Given a 2D Array (Python List), I need to find a new 1D such that it contains elements unique in each column. For example: [1, 1, -1, 1, 0] [1, -1, -1, 3, 4] [0, 0, 0, -2, -4] should give me for …

Extend Euclid Algorithm with matrix inverse mod N

I am implementing an extended Eucilid algorithm with matrix mod N. This is my code implementation: def eea(a, b): if not isinstance(a, int) or not isinstance(b, int) or not a or not b: …