Solved

Digit arrangement

Posted on 2006-11-13
7
1,393 Views
Last Modified: 2006-11-18
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
Comment
Question by:TheTechGuysNYC
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Author Comment

by:TheTechGuysNYC
ID: 17931065
Hint:

A few examples to help the process...

0123456789
0123456798
0123456897
0123456879

0
 
LVL 3

Author Comment

by:TheTechGuysNYC
ID: 17931072
Psuedocode is all that is needed to be correct...
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 100 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 32

Expert Comment

by:awking00
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

by:ozo
ID: 17933033
0
 
LVL 32

Accepted Solution

by:
awking00 earned 400 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

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This article describes how to reset your Windows 10 password when you've forgotten it.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question