Finding the smallest 'combination' of a number

Posted on 2003-03-20
Medium Priority
Last Modified: 2010-05-01
Hi! I need to do some 'puzzle' and I encounter problem when trying to figure out the smallest combination of a number. eg - I got the number 3412 and the number got 24 combination(1234, 1243, 1423, etc, etc). I want my app to find out the smallest value from the possible combination - 1234

Please advice with sample coding if possible.

Thank you,
Question by:aboka
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
  • Learn & ask questions
  • 2
LVL 26

Expert Comment

ID: 8174835

in your case numberofdigital=4

for i=1 to numberofdigital

combin = combin * i


Accepted Solution

Jacamar earned 160 total points
ID: 8174855
First sort the numbers

dim inLen as integer
dim array1() as integer
inLen = Len(stString)
redim array1(1 to inLen)
For inI = 1 to inLen
array1(inI) = mid(ststring,inI,1)
Next inI

For inI = 1 to inLen -1
 For inJ = 1 to inLen - inI
  if array1(inJ) > array1(inJ + 1) then
   inTemp = array1(inJ)
   array1(inJ) = array1(inJ + 1)
   array1(inJ + 1) = inTemp
  end if
 NExt inJ
Next inI

'  Now the numbers are sorted smallest to largest

For inI = 1 to inLen
mid(ststring,inI,1) = array1(inI)
Next inI

'  Now they are back in the string from smallest to largest

LVL 26

Expert Comment

ID: 8174915
Ignore will answer i misread the question

Author Comment

ID: 8175512
You are the BEST! Thank you very much,


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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