Skip to content

Instantly share code, notes, and snippets.

@datduyng
Last active December 14, 2018 03:26
Show Gist options
  • Select an option

  • Save datduyng/4b53819f1382efb8f362f778cfa317e5 to your computer and use it in GitHub Desktop.

Select an option

Save datduyng/4b53819f1382efb8f362f778cfa317e5 to your computer and use it in GitHub Desktop.
  • create class name 'cart'
Cart attribute
  int dx:
  int dy: 
  int state;
  int x,y; track coordinate on matrix
  /*
   if state == 1: turn left.(dx = -1)
   if state == 2: turn straight(dy = 1)
   if state == 3: turn right(dx = 1)
  */
  1. read input. store in matrix(150x150)
  • matrix representation
    • \/-| = '1'
    • + = '2' arbitary
    • ' '(blank) = '0'
    • if see '<|>|v|^|'
      • then create a object Cart. at that coor
  1. So now we have.
  • one matrix of the map.
  • an Array list of 'Cart' object.
  1. main Algorithm
  • Iterate through array list of object. update the coordinate of each object base on 'dx' and 'dy' attribute of each. by lookingat the map matrix
    • if object coor hit position with '2'(intersection) then update 'stage' attribute
  • If 2 object have same coordinate then exit return that coor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment