View Poll Results: Can you solve this?

Voters
7. You may not vote on this poll
  • Yes

    6 85.71%
  • No

    0 0%
  • Can't say

    1 14.29%
Multiple Choice Poll.
Results 1 to 20 of 20
Like Tree2Likes
  • 1 Post By PhHein
  • 1 Post By SurfMan

Thread: Array puzzle..

  1. #1
    Mayur Vachchewar is offline @mayurvachchewar
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    5
    Rep Power
    0

    Post Array puzzle..

    You are given an array A with elements 0 to n-1, numbers can be repeated in the array. Create n sets where

    S[i]={a[i],a[a[i]],a[a[a[i]]]…}. Set has all elements unique. Find the size of the largest set.

    Input:

    First line contains n, size of the array. n<1000

    Next lines contains n numbers, each element of the array

    Output

    Prints one number: Size of the largest set.

    Sample Test Case:

    Input: {3,1,2,0}

    Output: 2

    Explanation:

    Four possible sets are

    {3,0},{1},{2}{0,3}

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Array puzzle..

    Do you have a question?
    Mayur Vachchewar likes this.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Mayur Vachchewar is offline @mayurvachchewar
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    5
    Rep Power
    0

    Default Re: Array puzzle..

    yup! its an puzzle to solve..

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Array puzzle..

    But that's not a question, that's just a statement. I'm going to extend it: "it's a puzzle to solve by me". So why are you now posting your assignment? What are you expecting?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Array puzzle..

    I solved it!
    Mayur Vachchewar likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  6. #6
    Mayur Vachchewar is offline @mayurvachchewar
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    5
    Rep Power
    0

    Default Re: Array puzzle..

    Its an puzzle that assign me, so i need help to solve it.

  7. #7
    Mayur Vachchewar is offline @mayurvachchewar
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    5
    Rep Power
    0

    Default Re: Array puzzle..

    help me out also..

  8. #8
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Array puzzle..

    Define "help".
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  9. #9
    Mayur Vachchewar is offline @mayurvachchewar
    Join Date
    Jan 2014
    Location
    Pune
    Posts
    5
    Rep Power
    0

    Default Re: Array puzzle..

    Okay!
    I need the logic behind it.

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Array puzzle..

    Finished.

  11. #11
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Array puzzle..

    What's my prize for solving it?

  12. #12
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Array puzzle..

    Quote Originally Posted by Mayur Vachchewar View Post
    Okay!
    I need the logic behind it.
    Well think about it then!

    And just in case it hasn't sunk in yet: you're not going to get the answer handed to you. You do it, or nobody does it. But if you have a specific question, which can only be when you have done work yourself already, then feel free to ask it. If you don't understand the question (which I would understand, I had to read it a couple of times before I got the intention), I suggest you ask whoever gave you the assignment for clarification.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Array puzzle..

    Just to be clear, when you send me a pm containing the line "Waiting for the answer.", you really have no idea what people are trying to tell you. Read gimbal's explanation and try again.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

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

    Default Re: Array puzzle..

    Quote Originally Posted by superhaNds View Post
    What's my prize for solving it?
    Nothing, because I solved it first (I just didn't have the time to mention it).

    Now, hand over my loot.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Array puzzle..

    Quote Originally Posted by SurfMan View Post
    Just to be clear, when you send me a pm containing the line "Waiting for the answer.", you really have no idea what people are trying to tell you. Read gimbal's explanation and try again.
    Ugh. "Waiting for the answer" - really?

    My crystal ball is unfogging: I see a future in burger flipping.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  16. #16
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default Re: Array puzzle..

    Quote Originally Posted by gimbal2 View Post
    Ugh. "Waiting for the answer" - really?

    My crystal ball is unfogging: I see a future in burger flipping.
    Really? I think the requirements may be too high.

  17. #17
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Array puzzle..

    Don't know if this meets your requirements, but it's certainly worth running this one.

    Java Code:
    public class ArrayPuzzle {
        public static void main(String[] args) {
            int[] ap = {95046, 41664, 134106, 144522, 151032, 41664, 141918, 157542, 41664, 135408, 144522, 141918, 131502, 154938, 144522, 148428, 139314, 41664, 130200, 144522, 143220, 131502, 41664, 126294, 151032, 41664, 138012, 126294, 153636, 126294, 58590, 132804, 144522, 148428, 152334, 141918, 149730, 59892, 144522, 148428, 134106};
            int[] result = new int[ap.length];
            for (int i1 = 0; i1 < ap.length; i1++) {
                int k1 = ap[i1]/42;
                int kl = k1/31;
                int i = kl;
                result[i1] = i;
            }
            for (int i : result) {
                System.out.print( new StringBuilder().append(String.valueOf((char)Integer.parseInt(Integer.toString(i))).toString()));
            }
        }
    }
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2™ © 2013

  18. #18
    superhaNds is offline Senior Member
    Join Date
    Apr 2013
    Location
    Sweden
    Posts
    264
    Rep Power
    2

    Default Re: Array puzzle..

    Quote Originally Posted by JosAH View Post
    Nothing, because I solved it first (I just didn't have the time to mention it).

    Now, hand over my loot.

    kind regards,

    Jos


    No way, I'm long gone by now. But I could buy you some espresso.

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

    Default Re: Array puzzle..

    Quote Originally Posted by superhaNds View Post
    No way, I'm long gone by now. But I could buy you some espresso.
    Hogwash! Me, being the legitimate owner of the loot, I am going to spend it on sensible stuff, such as Grolsch (with the ceramic top!) and scantily clad women and, and, and ...

    kindest regards,

    Jos (<--- filthy rich)
    cenosillicaphobia: the fear for an empty beer glass

  20. #20
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,616
    Rep Power
    5

    Default Re: Array puzzle..

    Quote Originally Posted by Mayur Vachchewar View Post
    Four possible sets are

    {3,0},{1},{2}{0,3}
    Hmm. I only see three sets. (first and last are the same set).

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Peg Puzzle Solver GUI
    By Harlow777 in forum SWT / JFace
    Replies: 2
    Last Post: 11-11-2013, 03:48 PM
  2. Tromino puzzle
    By azertyazerty in forum New To Java
    Replies: 0
    Last Post: 03-23-2011, 03:50 PM
  3. 15 puzzle using 2d arrays
    By GPB in forum New To Java
    Replies: 1
    Last Post: 05-26-2010, 12:35 AM
  4. N-Puzzle Help!
    By evan42781 in forum New To Java
    Replies: 12
    Last Post: 04-29-2009, 11:34 PM
  5. Need help with Trees...(8-puzzle)
    By ventrue in forum New To Java
    Replies: 2
    Last Post: 03-23-2009, 11:04 PM

Tags for this Thread

Posting Permissions

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