Relative Content

Tag Archive for pythonalgorithm

Looking for algorithm to fit puzzle pieces into a 2D matrix

I have a game board which is a 2D array of letters – 6 x 8. The objective is to find a list of words with the length equal to X that complete the matrix without a letter being used twice. To create a word you can go up, down, left, right, and all diagonals. There is one word that going all the way from left to right, right to left, up to down, or down to up. This word describes the theme of the rest of the words.

Why is this algorithm O(n*n) – Manacher algorithm implementation?

So I was recently doing leetcode problem number 5 – longest palindromic substring, which outputs the longest palindromic substring out of a string. I have studied Manacher’s algorithm but I didn’t exactly remember it so I tried to recreate it from what I know.

BOS python script with closing prices

I have a list of closing prices for a symbol in python. I want to get the peaks and valleys – no problem – but I want to detect a break of a peak / valley that eiher made the last high / low. Here an example image:

Can’t increment the number N in this happy number algorithm

num=12345 H=[]*10 Happy=[]*100 def is_happy(Number): St= Number for i in range(len(St)): p=int(St[i]) V=p*p H.append(V) print(H) N+=H[len(H)-1-i] print(N) I’ve tried doing it directly on V but it didn’t work. I tried to get around the issue with a list H but it didn’t work, idk why I thought it would work but it did not. python […]

Can Python calculate the shareholding ratio of state-owned capital of tens of thousands of enterprises which have multi-tiered ownership structure?

I need to calculate the shareholding ratio of state-owned capital behind tens of thousands of enterprises which have multi-tiered ownership structure. Can Python accurately and efficiently achieve the results I want? If not, what other methods can achieve? I would appreciate valuable and constructive suggestions from experts.
(Example: 1. A and B hold 32.28% and 3.01% of C respectively; 2. D holds 100% of B; 3. State-owned enterprises E and F hold 90.01% and 9.99% of D respectively; 4. D and F hold 75% and 25% of A respectively; 5. B holds 100% of F. What is the final combined shareholding of E and F?)
The above example is just a textual expression. I have a more concise Excel file with the equity structure of each company.