Big update: Adding all advent of codes to same repo
This commit is contained in:
BIN
AdventOfCode2020/day3/day3.class
Normal file
BIN
AdventOfCode2020/day3/day3.class
Normal file
Binary file not shown.
70
AdventOfCode2020/day3/day3.java
Normal file
70
AdventOfCode2020/day3/day3.java
Normal file
@@ -0,0 +1,70 @@
|
||||
import java.util.Scanner;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
class day3 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
|
||||
File myFile = new File("input.txt");
|
||||
Scanner in = new Scanner(myFile);
|
||||
|
||||
String[] trees = new String[323];
|
||||
|
||||
int lineLength;
|
||||
|
||||
long multiple = 1;
|
||||
int numOfTrees = 0;
|
||||
|
||||
int x = 0;
|
||||
|
||||
for (int i = 0; i < 323; i++) {
|
||||
trees[i] = in.nextLine();
|
||||
}
|
||||
|
||||
lineLength = trees[0].length();
|
||||
|
||||
/*Part 1 code
|
||||
for (String line : trees) {
|
||||
|
||||
char current = line.charAt(x % lineLength);
|
||||
|
||||
if (current == '#') numOfTrees++;
|
||||
x = x + 3;
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
for (int dy = 1; dy < 3; dy++) {
|
||||
for (int dx = 1; dx < 8; dx = dx + 2) {
|
||||
|
||||
if (!(dy == 2 && dx > 1)) {
|
||||
numOfTrees = 0;
|
||||
x = 0;
|
||||
for (int i = 0; i < 323; i = i + dy) {
|
||||
char current = trees[i].charAt(x % lineLength);
|
||||
|
||||
if (current == '#') numOfTrees++;
|
||||
x = x + dx;
|
||||
|
||||
}
|
||||
System.out.println(numOfTrees);
|
||||
multiple *= numOfTrees;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println(multiple);
|
||||
|
||||
} catch (FileNotFoundException e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user