mirror of
https://github.com/Zormm/Advent-Of-Code-2022.git
synced 2026-02-26 07:26:51 +01:00
Added the Entrys for the Days 1 - 7
This commit is contained in:
@@ -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>
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Advent of Code 2022 Day 7</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>1671521328714</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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Directory {
|
||||
|
||||
private ArrayList<File> files;
|
||||
private ArrayList<Directory> directories;
|
||||
private Directory outerDirectory;
|
||||
private String name;
|
||||
|
||||
public Directory(String name, Directory outerDirectory) {
|
||||
files = new ArrayList<File>();
|
||||
directories = new ArrayList<Directory>();
|
||||
this.outerDirectory = outerDirectory;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Directory outerDirectory() {
|
||||
return outerDirectory;
|
||||
}
|
||||
|
||||
public void addElement(Object element) {
|
||||
if (element instanceof File) {
|
||||
files.add((File) element);
|
||||
}
|
||||
else if (element instanceof Directory) {
|
||||
directories.add((Directory) element);
|
||||
}
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int sum = 0;
|
||||
|
||||
for (File file : files) {
|
||||
sum += file.size();
|
||||
}
|
||||
|
||||
for (Directory directive : directories) {
|
||||
sum += directive.size();
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public Directory getInnerDirectory(String name) {
|
||||
for (Directory directory : directories) {
|
||||
if (directory.name().equals(name))
|
||||
return directory;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ArrayList<Directory> getAllInnerDirectories() {
|
||||
return directories;
|
||||
}
|
||||
|
||||
public ArrayList<Directory> getAllFolders() {
|
||||
ArrayList<Directory> folderList = new ArrayList<Directory>();
|
||||
|
||||
folderList.addAll(directories);
|
||||
|
||||
for (Directory e : directories)
|
||||
folderList.addAll(e.getAllFolders());
|
||||
|
||||
return folderList;
|
||||
}
|
||||
|
||||
public int countSum(int maximum) {
|
||||
int sum = 0;
|
||||
|
||||
for (Directory directive : this.getAllFolders()) {
|
||||
if (directive.size() <= maximum)
|
||||
sum += directive.countSum(maximum);
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
for (Directory directive : directories) {
|
||||
System.out.println(directive.size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
public class File {
|
||||
|
||||
private int size;
|
||||
private String name;
|
||||
|
||||
public File(int size, String name) {
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return size;
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,70 @@
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
public class main {
|
||||
|
||||
static Directory root;
|
||||
static Directory currentDirectory;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
root = new Directory("/", null);
|
||||
currentDirectory = root;
|
||||
|
||||
try {
|
||||
RandomAccessFile file = new RandomAccessFile("input.txt", "r");
|
||||
String str;
|
||||
|
||||
//Part 1
|
||||
System.out.print("Part 1: ");
|
||||
while ((str = file.readLine()) != null) {
|
||||
if (str.charAt(0) == '$') {
|
||||
command(str.substring(2));
|
||||
}
|
||||
else {
|
||||
if (str.substring(0,3).equals("dir")) {
|
||||
currentDirectory.addElement(new Directory(str.substring(4),currentDirectory));
|
||||
}
|
||||
else {
|
||||
int size = Integer.valueOf(str.substring(0,str.indexOf(" ")));
|
||||
String name = str.substring(str.indexOf(" ")+1);
|
||||
currentDirectory.addElement(new File(size, name));
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
|
||||
System.out.println(root.countSum(100000));
|
||||
//root.print();
|
||||
//Part 2
|
||||
System.out.print("Part 2: ");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void command(String command) {
|
||||
String handler = command.substring(0,2);
|
||||
if(handler.equals("ls"))
|
||||
return;
|
||||
|
||||
String content = command.substring(3);
|
||||
|
||||
switch (handler) {
|
||||
case "cd": cd(content); break;
|
||||
case "ls": ls(content); break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void cd(String content) {
|
||||
switch (content) {
|
||||
case "..": currentDirectory = currentDirectory.outerDirectory(); break;
|
||||
case "/": currentDirectory = root; break;
|
||||
default: currentDirectory = currentDirectory.getInnerDirectory(content);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ls(String content) {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user