Results 1 to 6 of 6
  1. #1
    Gembaknb is offline Member
    Join Date
    Mar 2017
    Posts
    1
    Rep Power
    0

    Default Need help to find permuted numbers in java

    It is seen that the number, 125874 and its double 251748, contain exactly the same digits, but in a different order. Write a java program to find and print the smallest positive integer, x such that 2x, 3x, 4x, 5x and 6x contain the same digits.

    This is the question. I tried to do only for 2x numbers. But very hard to do it.

    Java Code:
    public static void main(String[] args) 
    { 
    int num1=0, tmp1, num2, multi1, multi2, sum1, sum2, len1, len2; 
    do{ 
    num1++; 
    tmp1 = num1; 
    num2 = num1 * 2; 
    multi1 = 1; 
    multi2 = 1; 
    sum1 = 0;sum2 = 0;len1 = 0;len2 = 0; 
    while (tmp1 != 0) 
    { 
    multi1 *= ((tmp1 % 10 == 0) ?1: tmp1 % 10); 
    sum1 += (tmp1 % 10); 
    tmp1 /= 10; 
    len1++; 
    } 
    while (num2 != 0) 
    { 
    multi2 *= ((num2 % 10 == 0) ?1: num2 % 10); 
    sum2 += num2 % 10; 
    num2 /= 10; 
    len2++; 
    } 
    
    if (multi1 == multi2 && sum1==sum2 && len1==len2) 
    { 
    System.out.println("permuted"); 
    } 
    }while((multi1!=multi2) || (sum1!=sum2) || (len1!=len2)); 
    System.out.println(num1); 
    } 
    }


    This is the code I tried. Get multiple, sum and length. But some numerics such as 225, 225*2=450
    This also get the same multiplication, sum and number length. But they are not permuted.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,001
    Rep Power
    33

    Default Re: Need help to find permuted numbers in java

    Please post code with the proper indentations and some comments describing its logic.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Need help to find permuted numbers in java

    It's all over
    https://coderanch.com/t/677809/java/code-program
    Java Code Help - ElaKiri Community

    Also apparently posted and moderated out of existence at SO

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Need help to find permuted numbers in java

    Hey @OP, did you do a web search for permutation algorithms? You should get lots of hits.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Need help to find permuted numbers in java

    Use a digital expansion of 1/7

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Need help to find permuted numbers in java

    @OP, you don't need to do any math on this except for the required multiplication.
    In the solution, each number will have the same digits. So consider how using a
    sort method might help.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. How to find biggest two int. numbers from four
    By keimic53 in forum New To Java
    Replies: 5
    Last Post: 05-24-2014, 03:36 AM
  2. Can StreamTokenizer find numbers followed by letters
    By kbreitsprecher in forum New To Java
    Replies: 1
    Last Post: 03-08-2012, 10:45 PM
  3. Coding to find the Harshad numbers...
    By nope in forum New To Java
    Replies: 16
    Last Post: 03-07-2011, 04:16 AM
  4. Replies: 8
    Last Post: 02-08-2011, 07:27 AM
  5. Help with my code to find MinOfAll numbers
    By May.ver.rick in forum New To Java
    Replies: 9
    Last Post: 04-20-2010, 04:46 AM

Posting Permissions

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