This commit is contained in:
2020-12-02 16:24:07 -06:00
commit 9b46510667
4 changed files with 1292 additions and 0 deletions
+42
View File
@@ -0,0 +1,42 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
class DayTwo {
public static void main(String[] args) {
int count1 = 0;
try {
File inputFile = new File("input.txt");
Scanner readFile = new Scanner(inputFile);
while (readFile.hasNextLine()) {
int count2 = 0;
String whale = readFile.nextLine();
int lowerBound = Integer.parseInt(whale.substring(0, whale.indexOf("-")));
int upperBound = Integer.parseInt(whale.substring(whale.indexOf("-") + 1, whale.indexOf(":") - 2));
char inputKey = whale.charAt(whale.indexOf(":") - 1);
String password = whale.substring(whale.indexOf(":") + 1);
char[] passwordChar;
passwordChar = password.toCharArray();
for (int i = 0; i < passwordChar.length; i++) {
if (inputKey == passwordChar[i]) {
count2++;
}
}
if (passwordChar[lowerBound] == inputKey ^ passwordChar[upperBound] == inputKey) {
count1++;
}
System.out.println(lowerBound);
System.out.println(upperBound);
System.out.println(inputKey);
System.out.println(password);
System.out.println(count1);
}
readFile.close();
} catch (FileNotFoundException e) {
System.out.println("crap");
}
}
}
File diff suppressed because it is too large Load Diff