Algorithm Help for Java!

Discussion in 'Plugin Development' started by frrancis909, Jun 1, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    frrancis909

    Ok so say I have a region:
    - Each Region is 4 Units Wide (Ex: 1-4, 4-8, 8-12, ETC.)
    - Say I pick unit 3!
    - How would I make it know that Unit 3 belongs to region 1-4 AND be universal to work with any numbers?
    A fast response would help a lot!
     
  2. Offline

    Lolmewn

    unit / 4
    Let integer division do the work for you. Then it'll run from that number * 4 until (number+1) * 4 - 1
     
  3. Offline

    frrancis909

    How would I implement that though :/ Say you are at the cord X = 256 and you place a block down... It then does 256/4 then how can I make it do that rest?
     
  4. Offline

    Lolmewn

    frrancis909 Do what exactly? I'm not gonna spoonfeed you code, ya know.
     
  5. Offline

    frrancis909

    xD no like I mean its 64 now how do I make it so it knows what other integers are along in region 64
     
  6. Offline

    Lolmewn

    frrancis909 Exactly that ^
     
  7. Offline

    frrancis909

    Or just (X/4) Rounded to the nearest whole number and add 4?
     
  8. Offline

    Lolmewn

    frrancis909 Try it out I'd say ;) Just throw it in there and see what the output is.
     
  9. Offline

    frrancis909

    Wait no that does not work :/

    Lolmewn I have asked already 3 People on skype and we are all confused :/

    this is what we got

    It isn't quite working but it needs to be something like this:

    int y = 0;
    int x = 256;

    while(y != (x + 1) * 4 - 1)
    {
    y++;
    }

    System.out.println("Answer: " + y);

    We also found that alike regions divided have the same main integer so if 24-28 are alike they all have 6.XX

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  10. Mi might be wrong, but I believe what you are looking for is modulo (%):

    For example, with 4-wide regions:
    Code:
    int coordinate = ...;
     
    int region = coordinate / 4;
    int coordInRegion = coordinate % 4;
    For coordinate input 11, it would be region=2, coordInRegion=3.
    (note that coordinates 0-3 are in "region 0")
     
  11. Offline

    frrancis909

    We found that this works

    [/syntax]

    ugh, double answer = 4 * (Math.floor(Math.abs(x / 4)));

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 30, 2016
  12. Offline

    RawCode

  13. Offline

    frrancis909

    Well no then you can't find the region it is in.... and the numbers with the region it is in.
     
  14. Offline

    Necrodoom

    Region unit / 4 - unit / 4 + 3 as per your example at first post
     
Thread Status:
Not open for further replies.

Share This Page