You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.5 KiB
Java

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");
}
}
}