Added 2022 day 4 solutions and binaries

Changes to be committed:
	new file:   2022/day04/Day04A.class
	new file:   2022/day04/Day04A.java
	new file:   2022/day04/Day04B.class
	new file:   2022/day04/Day04B.java
	new file:   2022/day04/day04_algo.txt
	new file:   2022/day04/input.txt
This commit is contained in:
Gheiserton 2022-12-04 14:13:58 -05:00
parent f19c399ba6
commit 5a13f4f24a
6 changed files with 1056 additions and 0 deletions

BIN
2022/day04/Day04A.class Normal file

Binary file not shown.

28
2022/day04/Day04A.java Normal file
View file

@ -0,0 +1,28 @@
import java.util.Scanner;
import java.nio.file.Paths;
import java.io.IOException;
public class Day04A {
public static void main (String[] args) {
int rangeEnclosuresCount = 0;
try (Scanner inputFile = new Scanner(Paths.get("input.txt"))) {
while (inputFile.hasNext()) {
int[] rangeList = rangeLineIntegerification(inputFile.nextLine());
if ((rangeList[0] >= rangeList[2] && rangeList[1] <= rangeList[3]) || (rangeList[2] >= rangeList[0] && rangeList[3] <= rangeList[1])) {rangeEnclosuresCount++;}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("The number of fully enclosed ranges is: %d", rangeEnclosuresCount);
}
public static int[] rangeLineIntegerification(String textRanges) {
int[] intRanges = new int[4];
String[] ranges = textRanges.split("[,-]");
for (int i = 0; i < 4; i++) {
intRanges[i] = Integer.parseInt(ranges[i]);
}
return intRanges;
}
}

BIN
2022/day04/Day04B.class Normal file

Binary file not shown.

28
2022/day04/Day04B.java Normal file
View file

@ -0,0 +1,28 @@
import java.util.Scanner;
import java.nio.file.Paths;
import java.io.IOException;
public class Day04B {
public static void main (String[] args) {
int rangeEnclosuresCount = 0;
try (Scanner inputFile = new Scanner(Paths.get("input.txt"))) {
while (inputFile.hasNext()) {
int[] rangeList = rangeLineIntegerification(inputFile.nextLine());
if (Math.max(rangeList[0], rangeList[2]) <= Math.min(rangeList[1], rangeList[3])) {rangeEnclosuresCount++;}
}
} catch (IOException e) {
e.printStackTrace();
}
System.out.printf("The number of overlapping ranges is: %d", rangeEnclosuresCount);
}
public static int[] rangeLineIntegerification(String textRanges) {
int[] intRanges = new int[4];
String[] ranges = textRanges.split("[,-]");
for (int i = 0; i < 4; i++) {
intRanges[i] = Integer.parseInt(ranges[i]);
}
return intRanges;
}
}

View file

1000
2022/day04/input.txt Normal file

File diff suppressed because it is too large Load diff