Answer to Question #260183 in Python for hjkl

Question #260183

In a wedding that you are attending, there are some chairs that have digits inscribed at their



backs. The chairs are lined in a row such that they form a string of the digits. Find the



minimum number of sets M that can be formed from these digits such that:



1. The number of digits in each set is one gf more than one.



2. Each set is formed using consecutive digits and no digit can be used more than once.



3. In each set, the number formed using the digits is less than or equal to Y. using three inputs

1
Expert's answer
2021-11-02T17:35:43-0400
import math as mt
def minimumSets(X, M):
    count = 0
    Interger = 0
    Y = len(X)
    n = 0
    for i in range(Y):
        
        Interger = Interger * 10 + (ord(X[i]) - ord('0'))
 
        if (Interger <= M):
            n = 1
        else: 
            if (n):
                count += 1
            Interger = ord(X[i]) - ord('0')
            n = 0
            if (Interger <= M):
                n = 1
            else:
                Interger = 0
    if (n):
        count += 1
 
    return count
X = input("Enter the interger: ")
M = 30
print("The minimum number of sets is: ",minimumSets(X, M))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog