Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I have been assigned to write mathematical equation for permutation using only 1,3,5,7,9 numbers starting from single digit going up to five digits numbers. For example

Single digit 1 3 5 7 9 two digit 1,3 1,5 1,7 1,9 Please note 3,1 is treated same as 1,3, or 1,1,3 is same as 1,3,1 and 3,1,1 Thanks in Advance, Rodney

share|improve this question
    
Welcome to math.SE: since you are new, I wanted to let you know a few things about the site. In order to get the best possible answers, it is helpful if you say in what context you encountered the problem, and what your thoughts on it are; this will prevent people from telling you things you already know, and help them give their answers at the right level. If this is homework, please add the homework tag; people will still help, so don't worry. –  user53153 Jan 3 '13 at 8:13
    
Also, it is not quite clear what "write equation for permutation" even means. Does it mean an equation for the number of all possible permutations, or something else. You gave some two-digit examples but your list appears to be incomplete: why did not you list 3,5 or 3,7 etc? Carefully working through the case of two-digit permutations may give you an idea of what the formula should be. –  user53153 Jan 3 '13 at 8:18
    
Dear Guru, Thanks for your guidance. Sorry if I have confused you. Wondering if there is any Mathematical equation/formula to populate. Outcome results that I am looking for single digits, 1,3,5,7,9 , then move on to two digits 13,15,17,19,35,37,39,57,59, Three digits, 135,137,139,157,159,357,359,579, 113,115,117,119,331,335,337,339,551,553,557,559,771,773,775,779,991,993,995,997, then comes 4 digits and finally five digits. I am wondering if some mathematical equation is possible rather than doing manually. I appreciate your time and efforts for my question, Regards Rodney –  user55027 Jan 3 '13 at 23:34
    
Two unclear points: (A) Your 3-digit combinations allow repetitions: for example in 115 the digit 1 is used twice. Yet, in the 2-digit combinations you do not list 11, 33, 77, etc. Why is that? (B) If you are looking for a way to actually produce these patterns of digits (rather than just count how many there are), then you need an algorithm (presented in a programming language) rather than a mathematical formula. –  user53153 Jan 3 '13 at 23:39
    
Dear Guru,Thanks for guidance, you are are on spot on! I may require algorithm, 11,33,55, were missed inadvertently. –  user55027 Jan 4 '13 at 1:55
add comment

1 Answer

The details will depend on the language you are supposed to use. Here is how it could be done in JavaScript: the numbers 1,3,5,7,9 are treated as letters; they get appended to existing strings (oldStrings) as long as this does not put letters out of alphabetical order (e.g., after 15 we cannot put 3 but can put another 5). So there is a triple loop here: one by length of string, one goes over existing strings, and one looks for letters to append, checking the alphabetization condition oldStrings[i].charAt(len-2)<=letters[j]

var letters = ['1','3','5','7','9'];
var oldStrings = [''];
var newStrings = [];
var answer = '';
for (var len=1; len<=letters.length; len++) {
    for (var i=0; i<oldStrings.length; i++) {
        for (var j=0; j<letters.length; j++) {
            if (oldStrings[i].charAt(len-2)<=letters[j]) { 
            newStrings.push(oldStrings[i]+letters[j]);
            }
        }
    }
    answer=answer+'Strings of length '+len+' are '+newStrings.join()+'\n';
    oldStrings = newStrings;
    newStrings = [];
}
alert(answer);​

This is not the most efficient code, but it works. Since this is your assignment, my advice is to re-think and redo the problem in another language (e.g., Python) as to avoid a charge of plagiarism.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.