Created
December 3, 2018 06:29
-
-
Save gmay46/548adcdb56675ad9d2f9784b8be8f5a4 to your computer and use it in GitHub Desktop.
Advent_of_code_2018_3_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package advent_of_code_2018_3_1; | |
import java.io.BufferedReader; | |
import java.io.FileReader; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.stream.IntStream; | |
/** | |
* | |
* @author garrett | |
*/ | |
public class Advent_of_code_2018_3_1 { | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String[] args) throws IOException { | |
//[1] from left [2] from top | |
int[][] length_width = new int[1000][1000]; | |
int sq_in_count = 0; | |
List<String> input = new ArrayList(); | |
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\garrett\\Documents\\NetBeansProjects\\advent_of_code_2018_3_1\\src\\advent_of_code_2018_3_1\\input.txt")); | |
try { | |
String line = br.readLine(); | |
while (line != null) { | |
input.add(line); | |
line = br.readLine(); | |
} | |
for(int x=0; x < input.size();x++){ | |
String[] split_string_at = input.get(x).split("@"); | |
String[] split_string_colon = split_string_at[1].split(":"); | |
//[0] from left side [1] from top | |
String[] split_string_from_sides = split_string_colon[0].split(","); | |
//[0] wide [1] tall/deep | |
String[] split_string_area = split_string_colon[1].split("x"); | |
for(int y = Integer.parseInt(split_string_from_sides[0].trim()); | |
y < (Integer.parseInt(split_string_from_sides[0].trim())+Integer.parseInt(split_string_area[0].trim())); | |
y++){ | |
for(int z = Integer.parseInt(split_string_from_sides[1].trim()); | |
z < (Integer.parseInt(split_string_from_sides[1].trim())+Integer.parseInt(split_string_area[1].trim())); | |
z++){ | |
length_width[y][z]++; | |
} | |
} | |
} | |
for(int y = 0; y < length_width.length; y++){ | |
for(int z = 0; z < length_width.length; z++){ | |
if(length_width[y][z] >= 2){ | |
//System.out.println("y:"+y+" z:"+z+" contents:"+length_width[y][z]); | |
sq_in_count++; | |
} | |
} | |
} | |
System.out.println(sq_in_count); | |
} | |
finally { | |
br.close(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment