Results 1 to 14 of 14

- 01-26-2011, 11:21 PM #1Member
- Join Date
- Jan 2011
- Location
- philippines
- Posts
- 7

- Rep Power
- 0

- 01-26-2011, 11:26 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3

- Rep Power
- 8

Did you ask this question the other day? You need to develop a permutation method:

Permutation - Wikipedia, the free encyclopedia

- 01-27-2011, 11:28 PM #3Member
- Join Date
- Jan 2011
- Location
- philippines
- Posts
- 7

- Rep Power
- 0

awts!!!!.... i dnt understand..... can u give me some hint!!....

- 01-27-2011, 11:43 PM #4
A hint???

Other than a link to the Wiki page explaining permutations? Did you even bother to read it or do you just want someone to spoonfeed you the code?

- 01-27-2011, 11:49 PM #5Member
- Join Date
- Dec 2010
- Posts
- 21

- Rep Power
- 0

- 01-27-2011, 11:50 PM #6
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3

- Rep Power
- 8

The idea of a permutation is to re-arrange some input into every possible re-arrangement.

for the number 123, when you apply the permutation it should output:

123, 213, 231,

321. 312. 132.

Do you notice any pattern that seems to be re-occurring?

I split it into 2 lines, look at how the one is moving in the first line. To find out how many combination's there will be in a number after permutation you use factorials, if the item has a length of 3, it would be 3 * 2 * 1 = 6 possible changes.

Permutations are pretty challenging, and I'd have to sit down and think about how to do them in java, but just use what I said here and try to think how you would do it yourself.

You can split the number you are applying this to with % and /, it would probably also be easier to temporarily set them as strings.

Also, try using some other numbers and solving it by hand, then take what you did an translate it to java.

I gave you a lot to go on, and I will admit that permutations are fairly challenging, so just take your time, think everything through, read more about it on the wiki page and just keep considering how to do it.

- 01-28-2011, 03:12 AM #7Member
- Join Date
- Jan 2011
- Posts
- 3

- Rep Power
- 0

This is interesting! I'll give you a hint. There's a math formula for this, apply it in your java code.

- 01-28-2011, 06:32 AM #8Member
- Join Date
- Jan 2011
- Location
- philippines
- Posts
- 7

- Rep Power
- 0

tnx master I get the pattern!!!... but so hard to code the frmula in java!!!... but i will try my best!!!... btw tnx...

- 01-28-2011, 08:19 AM #9Senior Member
- Join Date
- Jan 2011
- Location
- Bangalore, India
- Posts
- 102

- Rep Power
- 0

## a tricky way out (may not be the most intelligent way)

Apart from formula, I think you can also do something like this.

Java Code:String number1 = "1"; String number3 = "3"; String number7 = "7"; // Dont hardcode like i have shown above. Put each number to each string. find out the way to convert Integer to String for (int i = 100; i < 1000; i++) { String testNumber = convertToString(i); //find out the way to convert Integer to String //now testNumber will contain something like "137" or "138" till "999" if ( testNumber.contains(number1) && testNumber.contains(number3) && testNumber.contains(number7)) //Remember, there is no method called contains. Find it out yourself. { System.out.println(testNumber); } }

- 01-28-2011, 08:37 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 13,648
- Blog Entries
- 7

- Rep Power
- 21

I supplied working code in this thread.

kind regards,

Jos**cenosillicaphobia**:*the fear for an empty beer glass*

- 01-29-2011, 05:02 AM #11Member
- Join Date
- Jan 2011
- Location
- philippines
- Posts
- 7

- Rep Power
- 0

ahh tnx!!!!.... actually this is the whole tread..

A number is "prime" if it has no divisors other than itself and1. For example, 23 is prime

and 35 is not prime because 35 = 7 x 5. If the digits of a number are rearranged, then

usually its primeness changes - for example, 32 is not prime but 53 is. For this problem,

you have to find numbers which are prime no matter how you rearrange their digits. For

example, all of the numbers 113, 131 and 311are prime, so we say that 113 is an

"anagrammatic prime" (also 131 and 311 are anagrammatic primes).

Input will be from standard input and will consist of lines with a single positive number, n,

less than 10,000,000, on each line. You must find the first anagrammatic prime which is

bigger than n and less than the next power of 10 above n. The input will be terminated

by a line consisting of a single 0.

Output, which must be written to standard output, must be one number for each number

in the input. The number must either be the next anagrammatic prime, as described

above or 0 if there is no anagrammatic prime in the range defined.

Example

Input

10

16

900

113

0

Output

11

17

919

131

0

- 01-29-2011, 10:59 PM #12
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3

- Rep Power
- 8

Were you able to solve it?

- 01-30-2011, 05:28 AM #13Member
- Join Date
- Jan 2011
- Location
- philippines
- Posts
- 7

- Rep Power
- 0

yes!!!.. so hard to code for me!... i know how to get the prime num!... but i dnt know how to get a anagrammatic prime.... that's why i ask on how to get a ramble input.... anyOne can help me..

- 01-30-2011, 08:20 AM #14
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 13,648
- Blog Entries
- 7

- Rep Power
- 21

## Bookmarks