Renamed Folders and added Idea for Day 19

This commit is contained in:
Jona Krampe
2022-12-20 15:06:07 +00:00
parent 6d6ff4f162
commit e8a2145715
47 changed files with 51 additions and 1043 deletions
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
+28
View File
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Advent of Code 2022 Day 4</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<filteredResources>
<filter>
<id>1671521328698</id>
<name></name>
<type>30</type>
<matcher>
<id>org.eclipse.core.resources.regexFilterMatcher</id>
<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
</matcher>
</filter>
</filteredResources>
</projectDescription>
@@ -0,0 +1,14 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
+1000
View File
File diff suppressed because it is too large Load Diff
+51
View File
@@ -0,0 +1,51 @@
import java.io.IOException;
import java.io.RandomAccessFile;
public class main {
public static void main(String[] args) {
try {
RandomAccessFile file = new RandomAccessFile("Input.txt", "r");
String str;
int indexOfSeperator = 0, indexOfFirstDash = 0, indexOfSecondDash = 0;
int sectionBeginningElf1, sectionEndingElf1, sectionBeginningElf2, sectionEndingElf2;
int countPart1 = 0, countPart2 = 0;
while ((str = file.readLine()) != null) {
indexOfSeperator = str.indexOf(",");
indexOfFirstDash = str.indexOf("-");
indexOfSecondDash = str.indexOf("-", indexOfFirstDash+1);
sectionBeginningElf1 = Integer.valueOf(str.substring(0, indexOfFirstDash));
sectionEndingElf1 = Integer.valueOf(str.substring(indexOfFirstDash+1,indexOfSeperator));
sectionBeginningElf2 = Integer.valueOf(str.substring(indexOfSeperator+1, indexOfSecondDash));
sectionEndingElf2 = Integer.valueOf(str.substring(indexOfSecondDash+1));
// Part 1
if ((sectionBeginningElf1 <= sectionBeginningElf2 && sectionEndingElf1 >= sectionEndingElf2)
|| (sectionBeginningElf2 <= sectionBeginningElf1 && sectionEndingElf2 >= sectionEndingElf1)) {
countPart1++;
}
// Part 2
if (between(sectionBeginningElf1, sectionBeginningElf2, sectionEndingElf2) || between(sectionEndingElf1, sectionBeginningElf2, sectionEndingElf2) || between(sectionBeginningElf2, sectionBeginningElf1, sectionEndingElf1) || between(sectionEndingElf2, sectionBeginningElf1, sectionEndingElf1)) {
countPart2++;
}
//System.out.println(sectionBeginningElf1 + " " + sectionEndingElf1 + " - " + sectionBeginningElf2 + " " + sectionEndingElf2);
}
System.out.println("Part 1: " + countPart1);
System.out.println("Part 2: " + countPart2);
file.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean between(int variable, int minValueInclusive, int maxValueInclusive) {
return variable >= minValueInclusive && variable <= maxValueInclusive;
}
}