Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- import java.util.ArrayList;
- //import java.util.Hashtable;
- public class PresentDelivery {
- static int x = 0;
- static int y = 0;
- static int xr = 0;
- static int yr = 0;
- static boolean repeat = false;
- static int housesVisited = 0;
- static boolean robot = false;
- static ArrayList<Integer> XValues = new ArrayList<Integer>();
- static ArrayList<Integer> YValues = new ArrayList<Integer>();
- public static void main(String[] args) throws IOException {
- // TODO Auto-generated method stub
- //housesVisited++;
- for(String line : Files.readAllLines(Paths.get("C:/Users/Gregorio21/Desktop/Advent.txt"))){
- for(char chars : line.toCharArray()){
- if(robot){
- robot = false;
- if(chars == '^'){
- yr++;
- }
- else if(chars == 'v'){
- yr--;
- }
- else if(chars == '>'){
- xr++;
- }
- else if(chars == '<'){
- xr--;
- }
- for(int i = 0; i < XValues.size(); i++){
- if(XValues.get(i) == xr && YValues.get(i) == yr){
- repeat = true;
- }
- }
- if(!repeat){
- housesVisited ++;
- }
- XValues.add(xr);
- YValues.add(yr);
- repeat = false;
- }
- else if(!robot){
- robot = true;
- if(chars == '^'){
- y++;
- }
- else if(chars == 'v'){
- y--;
- }
- else if(chars == '>'){
- x++;
- }
- else if(chars == '<'){
- x--;
- }
- for(int i = 0; i < XValues.size(); i++){
- if(XValues.get(i) == x && YValues.get(i) == y){
- repeat = true;
- }
- }
- if(!repeat){
- housesVisited ++;
- }
- XValues.add(x);
- YValues.add(y);
- repeat = false;
- }
- }
- }
- System.out.println(housesVisited);
- }
- /*public static void housesVisited(int xMove, int yMove){
- if(xMove != 0){
- if(xMove == -previousx && !vertical){
- }
- else{
- housesVisited++;
- }
- previousx = xMove;
- horizontal = true;
- vertical = false;
- }
- else if(yMove != 0){
- if(yMove == -previousy && !horizontal){
- }
- else{
- housesVisited++;
- }
- previousy = yMove;
- vertical = true;
- horizontal = false;
- }
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement