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 2: That was fun right? Let's do another one! (35 points)
First see if you can design an algorithm that takes as input a 9 digit number where no digit appears twice and produces as output an arrangement of the
same 9 digits corresponding to the next highest number. If no such number exists, the algorithm should indicate this. So for example if the input is
781623954 the output would be 781624359. 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 1 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 781623954. Let's just call that number n for now. Add one to n to get n+1 and check to see if n+1 is
an acceptable answer.
What does it mean to be an acceptable answer?
It means every digit that appears in n also appears in the new number and that the new number is also a 9-digit number. In this case n+1 would be
Notice that the digit 4 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 n+2 is an acceptable answer. We keep going until we find an acceptable answer or we get to a 10-digit number.
For this question we will try 5 different test cases each worth 5 points. Here's three of the test cases we will try:
123456789
923456780
987541203
The algorithm that you wright down is also worth 5 points. Remember it's okay if your Python program is not an implementation of your algorithm but I
want you to submit both.
* * * Avoid using: break and sets Problem 2 :

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!