Initialize Project and add Solution for day 1 part 1
This commit is contained in:
commit
5e4c23281a
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
target/
|
||||
pom.xml.tag
|
||||
pom.xml.releaseBackup
|
||||
pom.xml.versionsBackup
|
||||
pom.xml.next
|
||||
release.properties
|
||||
dependency-reduced-pom.xml
|
||||
buildNumber.properties
|
||||
.mvn/timing.properties
|
||||
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
|
||||
# Eclipse m2e generated files
|
||||
# Eclipse Core
|
||||
.project
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
# Intellij Idea
|
||||
.idea
|
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Advent of Code in Java ☕
|
||||
|
||||
## Usage
|
||||
1. fork this Repository
|
||||
2. Install dependencies
|
||||
- [Maven](https://maven.apache.org/install.html)
|
||||
- [Java 17](https://www.oracle.com/java/technologies/downloads/#java17)
|
||||
3. Create file `day1.txt` with puzzle input in `input` folder
|
||||
4. Run the project 🚀 with `mvn package && java -cp target/AdventOfCode-1.0-SNAPSHOT.jar de.dhbw.horb.App`
|
||||
- or open and run in your favorite IDE
|
0
input/.gitkeep
Normal file
0
input/.gitkeep
Normal file
18
pom.xml
Normal file
18
pom.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>de.dhbw.horb</groupId>
|
||||
<artifactId>AdventOfCode</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<name>AdventOfCode</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
46
src/main/java/de/dhbw/horb/App.java
Normal file
46
src/main/java/de/dhbw/horb/App.java
Normal file
@ -0,0 +1,46 @@
|
||||
package de.dhbw.horb;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
/**
|
||||
* Advent of Code with sample Solution for Day 1 (Part 1)
|
||||
*/
|
||||
public class App
|
||||
{
|
||||
public static void main( String[] args )
|
||||
{
|
||||
String input = readInput("day1.txt");
|
||||
int total = 0;
|
||||
for(String line : input.split("\n")) {
|
||||
char last = 0;
|
||||
char first = 0;
|
||||
//Get last number
|
||||
for(int i = 0; i < line.length(); i++){
|
||||
char c = line.charAt(i);
|
||||
if(Character.isDigit(c)){
|
||||
last = c;
|
||||
}
|
||||
}
|
||||
//Get first
|
||||
for(int i = line.length() - 1; i >= 0; i--){
|
||||
char c = line.charAt(i);
|
||||
if(Character.isDigit(c)){
|
||||
first = c;
|
||||
}
|
||||
}
|
||||
//Parse and add:
|
||||
total += Integer.parseInt(Character.toString(first) + Character.toString(last));
|
||||
}
|
||||
System.out.println(total);
|
||||
}
|
||||
|
||||
public static String readInput(String filename) {
|
||||
try{
|
||||
return Files.readString(Paths.get(System.getProperty("user.dir"), "input", filename));
|
||||
} catch (IOException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user