# Thread: Find all permutations of a number

1. Member Join Date
Nov 2008
Posts
67
Rep Power
0

## Find all permutations of a number

I have a an integer, n, that is equal to 1379. I want to create an array of all the permutations of n (1397, 1739, 1793, 1937, 1973, 3179, etc...). How would I code this?

Note: I know how many permutations exist. Call that variable "tPerms" 2. ## At your current level, I'd bet you'd be able to solve this without our help. Why not first give it a go? Also, myself, I'd use characters or String representations of the numbers since we're not really treating these things as numbers. 3. ##  Originally Posted by matzahboy I have a an integer, n, that is equal to 1379. I want to create an array of all the permutations of n (1397, 1739, 1793, 1937, 1973, 3179, etc...). How would I code this?

Note: I know how many permutations exist. Call that variable "tPerms"
What you have tried so far, can you show us here? 4. Member Join Date
Nov 2008
Posts
67
Rep Power
0

## I found the following code (courtesy of Permutations.java). For the particular problem I'm trying to do, I need to find the 1000000th permutation. How would I modify this code to do that?

Java Code:
```// print N! permutation of the characters of the string s (in order)
public  static void perm1(String s) { perm1("", s); }
private static void perm1(String prefix, String s) {
int N = s.length();
if (N == 0) System.out.println(prefix);
else {
for (int i = 0; i < N; i++)
perm1(prefix + s.charAt(i), s.substring(0, i) + s.substring(i+1, N));
}

}``` 5. ## hhhmmm...

• Do you know what that piece of code does?
• Do you know what the "prefix" and "s" variables are? What they represent?

CJSL 6. Senior Member Join Date
Sep 2008
Posts
564
Rep Power
12

## I don't understand what the 1 millionth (or nth) permutation means. There is no order to permutations. 7. Member Join Date
Nov 2008
Posts
67
Rep Power
0

## I'm basically trying to solve problem 24 of project euler (Problem 24 - Project Euler) #### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•