[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
Solved

# Digit arrangement

Posted on 2006-11-13
Medium Priority
1,514 Views
Try this simple algorithm on for size.

Design an algorithm that, when given an arrangement of the digits 0,1,2,3,4,5,6,7,8,9, rearranges the digits so that the new arrangement represents the next larger value that can be represented by these digits (or reports that no such rearrangement exists if no rearrangement produces a larger value). Thus 5647382901 would produce 5647382910.
0
Question by:TheTechGuysNYC
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2
• 2

LVL 3

Author Comment

ID: 17931065
Hint:

A few examples to help the process...

0123456789
0123456798
0123456897
0123456879

0

LVL 3

Author Comment

ID: 17931072
Psuedocode is all that is needed to be correct...
0

LVL 84

Assisted Solution

ozo earned 400 total points
ID: 17932774
#!/usr/bin/perl
sub permute {
my (\$hold, @items) = @_;
print("@items\n"), return if \$hold+1==@items;
foreach \$i (\$hold..\$#items) {
@items[\$hold, \$i] = @items[\$i, \$hold];
permute(\$hold+1, @items);
}
}
@arr=(0..9);
permute(0, @arr);
0

LVL 32

Expert Comment

ID: 17932823
Are you sure you don't mean for your examples to be like this?
0123456789
0123456798
0123456879
0123456897
0

LVL 84

Expert Comment

ID: 17933033
0

LVL 32

Accepted Solution

awking00 earned 1600 total points
ID: 17933204
In pseudo code -
Add 9 to the number to get a new number
If the sum of the digits of the new number does not = 45
then continue adding 9 until they do.
0

LVL 84

Expert Comment

ID: 17933904
adding 9 until the sum = 45 will get you to 123456888, which is not a rearangement
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s time for spooky stories and consuming way too much sugar, including the many treats we’ve whipped for you in the world of tech. Check it out!
If something goes wrong with Exchange, your IT resources are in trouble.All Exchange server migration processes are not designed to be identical and though migrating email from on-premises Exchange mailbox to Cloud’s Office 365 is relatively simple…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
###### Suggested Courses
Course of the Month14 days, 19 hours left to enroll