Results 1 to 14 of 14
  1. #1
    jhon123 is offline Member
    Join Date
    Jan 2011
    Location
    philippines
    Posts
    7
    Rep Power
    0

    Default help me please!!!.. im new in java..

    guys can u help me this!!!..


    int n=137;

    and i want to display like this!!!...

    173,371,317,731,713

    one variable each of them...

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Did you ask this question the other day? You need to develop a permutation method:
    Permutation - Wikipedia, the free encyclopedia

  3. #3
    jhon123 is offline Member
    Join Date
    Jan 2011
    Location
    philippines
    Posts
    7
    Rep Power
    0

    Default

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

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    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?

  5. #5
    Jojomofoman is offline Member
    Join Date
    Dec 2010
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by jhon123 View Post
    awts!!!!.... i dnt understand..... can u give me some hint!!....
    It looks like a pretty good hint to me! How're you going to learn if he tells you exactly how to do it :D

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  7. #7
    adela is offline Member
    Join Date
    Jan 2011
    Posts
    3
    Rep Power
    0

    Default

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

  8. #8
    jhon123 is offline Member
    Join Date
    Jan 2011
    Location
    philippines
    Posts
    7
    Rep Power
    0

    Default

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

  9. #9
    subith86 is offline Senior Member
    Join Date
    Jan 2011
    Location
    Bangalore, India
    Posts
    102
    Rep Power
    0

    Wink 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);
    	}
    }

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    I supplied working code in this thread.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  11. #11
    jhon123 is offline Member
    Join Date
    Jan 2011
    Location
    philippines
    Posts
    7
    Rep Power
    0

    Default

    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
    

  12. #12
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Were you able to solve it?

  13. #13
    jhon123 is offline Member
    Join Date
    Jan 2011
    Location
    philippines
    Posts
    7
    Rep Power
    0

    Default

    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..

  14. #14
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,368
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by jhon123 View Post
    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..
    Did you read the link of the other thread I pointed to? There's code overthere that can generate all permutations in lexicographical order.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Posting Permissions

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