Question: * * * Avoid using: break and sets Problem 2 : That was fun right? Let's do another one! ( 3 5 points ) First
Avoid using: break and sets
Problem : That was fun right? Let's do another one! points
First see if you can design an algorithm that takes as input a digit number where no digit appears twice and produces as output an arrangement of the
same digits corresponding to the next highest number. If no such number exists, the algorithm should indicate this. So for example if the input is
the output would be You can use bulleted english to describe your algorithm or pseudocode similar to what we saw in class.
Now write a program in Python to do this task. You may find that the algorithm that you constructed above is difficult to implement but following a kind of
brute force approach similar to that in Problem is not too tough.
What the hell do you mean? Spoiler alert: algorithmic solution follows.
Suppose the input is as in the example above, namely Let's just call that number for now. Add one to to get and check to see if is
an acceptable answer.
What does it mean to be an acceptable answer?
It means every digit that appears in also appears in the new number and that the new number is also a digit number. In this case would be
Notice that the digit appears in the original number but not in the new number. So the new number fails. Add one more to that so that now
we're going to check to see if is an acceptable answer. We keep going until we find an acceptable answer or we get to a digit number.
For this question we will try different test cases each worth points. Here's three of the test cases we will try:
The algorithm that you wright down is also worth points. Remember it's okay if your Python program is not an implementation of your algorithm but I
want you to submit both.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
