Big update: Adding all advent of codes to same repo

This commit is contained in:
2024-12-06 00:14:09 +00:00
parent 5116bd4696
commit 233dda4fe9
106 changed files with 7790 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,63 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
class day5 {
public static void main(String[] args) {
File inputs = new File("input.txt");
try {
Scanner in = new Scanner(inputs);
String[] input = new String[884];
for (int i = 0; i < 884; i++) input[i] = in.nextLine();
int highest = 0;
int lowest = 99999999;
ArrayList<Integer> seatIDs = new ArrayList<Integer>();
for (String line : input) {
int row = binaryConvertion(line.substring(0, line.length() - 3), 'B');
int collumn = binaryConvertion(line.substring(line.length() - 3), 'R');
int calculation = row * 8 + collumn;
if (calculation > highest) highest = calculation;
else if (calculation < lowest) lowest = calculation;
seatIDs.add(calculation);
}
for (int i = lowest; i <= highest; i++) {
if (seatIDs.contains(i) == false) {
System.out.println(i);
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public static int binaryConvertion(String givenInputs, char one) {
int counter = 0;
for (int i = givenInputs.length() - 1; i >= 0; i--) {
if (givenInputs.charAt(i) == one) {
counter += Math.pow(2, givenInputs.length() - i - 1);
}
}
return counter;
}
}