diff --git a/java/.gitignore b/java/.gitignore new file mode 100644 index 0000000..d1ef781 --- /dev/null +++ b/java/.gitignore @@ -0,0 +1 @@ +Problem.class \ No newline at end of file diff --git a/java/2015/1/Problem.java b/java/2015/1/Problem.java new file mode 100644 index 0000000..fba1081 --- /dev/null +++ b/java/2015/1/Problem.java @@ -0,0 +1,29 @@ +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +public class Problem { + public static void main(String[] args) { + try { + char[] input = new String(Files.readAllBytes(Paths.get("../../../data/2015/1/input.txt"))).toCharArray(); + int floor = 0; + for (int i = 0; i < input.length; i++) { + if (input[i] == '(') floor++; + else floor--; + } + System.out.println("Part 1: " + floor); + + floor = 0; + int steps = 0; + for (int i = 0; i < input.length; i++) { + if (input[i] == '(') floor++; + else floor--; + steps++; + if (floor < 0) break; + } + System.out.println("Part 2: " + steps); + } catch (IOException ex) { + System.out.println(ex); + } + } +} diff --git a/java/bin/run b/java/bin/run new file mode 100755 index 0000000..772f560 --- /dev/null +++ b/java/bin/run @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +year=$1 +day=$2 + +javac $year/$day/Problem.java && cd $year/$day && time java Problem