Need help with a java array...

Discussion in 'OT Technology' started by marscheese, Oct 18, 2003.

  1. marscheese

    marscheese Guest

    alright, I have a rather lengthy project, and one of the things I have to do in it, it create a method that will rotate layers of an array. There is no pre-set size of the array, so the method have to be fairly general. Here's an example of what I have to do:

    Take the multidimentional array:
    ABCDE
    FGHIJ
    KLMNO
    12345
    67890

    Layer one would be: ABCDEJO5098761KF
    Layer two would be: GHIN432L
    Layer three is: M

    Now, the two-dimentional array is always square, that is, it's always 2x2, or 4x4, 15x15...whatever.

    What I have to do is rotate the layers of the array clockwise by some amount.

    For example, rotating layer one by 3, and layer two by 1 would look like this:

    (Origional)
    ABCDE
    FGHIJ
    KLMNO
    12345
    67890

    (Rotated)

    1KFAB
    6LGHC
    72MID
    834NE
    905OJ

    I hope this makes sense... I just really have no idea where to start. Anyone here have any suggestions?
     
  2. crotchfruit

    crotchfruit Guest

    funny, this was one of the questions in a topcoder round once. i tried to find the results, but it looks like database was either lost or cleaned, because they don't have records of the actual code anymore :(

    when i approached the problem i couldn't think of any special trick, and just brute forced it pretty ungracefully.
     

Share This Page