summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--day14/day14.java189
-rw-r--r--day14/input100
-rw-r--r--day14/test10
3 files changed, 299 insertions, 0 deletions
diff --git a/day14/day14.java b/day14/day14.java
new file mode 100644
index 0000000..000fc5e
--- /dev/null
+++ b/day14/day14.java
@@ -0,0 +1,189 @@
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+
+public class day14 {
+ public static void main(String args[]) throws IOException {
+ RandomAccessFile input = new RandomAccessFile("input", "r");
+ System.out.println("Day 14 Part 1: " + part1(input));
+ input.seek(0);
+ System.out.println("Day 14 Part 2: " + part2(input));
+ input.close();
+ }
+
+ public static String part1(RandomAccessFile input) throws IOException {
+ ArrayList<ArrayList<Tile>> platform = new ArrayList<>();
+
+ String line;
+ while ((line = input.readLine()) != null) {
+ ArrayList<Tile> row = new ArrayList<>();
+ for (char ch: line.toCharArray()) {
+ switch (ch) {
+ case 'O':
+ row.add(Tile.Round);
+ break;
+ case '#':
+ row.add(Tile.Cube);
+ break;
+ case '.':
+ row.add(Tile.Empty);
+ break;
+ }
+ }
+ platform.add(row);
+ }
+
+ tipNorth(platform);
+
+ int load = 0, rows = platform.size();
+ for (int r = 0; r < rows; r++) {
+ for (Tile t: platform.get(r)) {
+ if (t == Tile.Round) {
+ load += (rows - r);
+ }
+ }
+ }
+
+ return Integer.toString(load);
+ }
+
+ public static String part2(RandomAccessFile input) throws IOException {
+ return "WIP";
+ /*
+ ArrayList<ArrayList<Tile>> platform = new ArrayList<>();
+
+ String line;
+ while ((line = input.readLine()) != null) {
+ ArrayList<Tile> row = new ArrayList<>();
+ for (char ch: line.toCharArray()) {
+ switch (ch) {
+ case 'O':
+ row.add(Tile.Round);
+ break;
+ case '#':
+ row.add(Tile.Cube);
+ break;
+ case '.':
+ row.add(Tile.Empty);
+ break;
+ }
+ }
+ platform.add(row);
+ }
+
+ for (long l = 0; l < 1000000000; l++) {
+ tipNorth(platform);
+ tipWest(platform);
+ tipSouth(platform);
+ tipEast(platform);
+ }
+
+ int load = 0, rows = platform.size();
+ for (int r = 0; r < rows; r++) {
+ for (Tile t: platform.get(r)) {
+ if (t == Tile.Round) {
+ load += (rows - r);
+ }
+ }
+ }
+
+ return Integer.toString(load);
+ */
+ }
+
+ static enum Tile {
+ Round,
+ Cube,
+ Empty
+ }
+
+ private static void tipNorth(ArrayList<ArrayList<Tile>> platform) {
+ int rows = platform.size(), cols = platform.get(0).size();
+ for (int r = 0; r < rows; r++) {
+ for (int c = 0; c < cols; c++) {
+ if (platform.get(r).get(c) != Tile.Round) {
+ continue;
+ }
+
+ int rat = r;
+ while (rat > 0) {
+ if (platform.get(rat - 1).get(c) == Tile.Empty) {
+ platform.get(rat - 1).set(c, Tile.Round);
+ platform.get(rat).set(c, Tile.Empty);
+ rat -= 1;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ private static void tipSouth(ArrayList<ArrayList<Tile>> platform) {
+ int rows = platform.size(), cols = platform.get(0).size();
+ for (int r = (rows - 1); r >= 0; r--) {
+ for (int c = 0; c < cols; c++) {
+ if (platform.get(r).get(c) != Tile.Round) {
+ continue;
+ }
+
+ int rat = r;
+ while (rat < (rows - 1)) {
+ if (platform.get(rat + 1).get(c) == Tile.Empty) {
+ platform.get(rat + 1).set(c, Tile.Round);
+ platform.get(rat).set(c, Tile.Empty);
+ rat += 1;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private static void tipWest(ArrayList<ArrayList<Tile>> platform) {
+ int rows = platform.size(), cols = platform.get(0).size();
+ for (int r = 0; r < rows; r++) {
+ for (int c = 0; c < cols; c++) {
+ if (platform.get(r).get(c) != Tile.Round) {
+ continue;
+ }
+
+ int cat = c;
+ while (cat > 0) {
+ if (platform.get(r).get(cat - 1) == Tile.Empty) {
+ platform.get(r).set(cat - 1, Tile.Round);
+ platform.get(r).set(cat, Tile.Empty);
+ cat -= 1;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ private static void tipEast(ArrayList<ArrayList<Tile>> platform) {
+ int rows = platform.size(), cols = platform.get(0).size();
+ for (int r = 0; r < rows; r++) {
+ for (int c = (cols - 1); c >= 0; c--) {
+ if (platform.get(r).get(c) != Tile.Round) {
+ continue;
+ }
+
+ int cat = c;
+ while (cat < (cols - 1)) {
+ if (platform.get(r).get(cat + 1) == Tile.Empty) {
+ platform.get(r).set(cat + 1, Tile.Round);
+ platform.get(r).set(cat, Tile.Empty);
+ cat += 1;
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+ */
+}
diff --git a/day14/input b/day14/input
new file mode 100644
index 0000000..ca6e694
--- /dev/null
+++ b/day14/input
@@ -0,0 +1,100 @@
+O#...OO.#.#..##.#..#O.OO...O##OO.......#......O.O...O..........O..#O..O.#.#.O.....##O.#O.##.........
+.OOO..OOO.O.#.....#.....#.#.....O..#..OO..#.....O#O##..##O#.OO....O##.OOO..O...#....O....#O..#...O..
+OOO#...O#...##.OOOO##.O..#.....O...#.O..#...#.O..OO..##.#....O#O..#O#..##...O.OO..#.#........#O....O
+O..#..#...#.O##.......OO#.#....O.##.O..O.O#.O..O#.....#...O..OO.O.#......O.###.........#.......##...
+..O.O.O..#O..OOOO..#..#..O..O#O...O....#.O#........OOO#.O...O..O#.#.O........#......#O.O...OO.#.O..O
+#..O.#..##....#...O..........#..O.#..##.O.....O.O.O..O..O.O.#.OO#.#..##.........#OO.O....##...#..##.
+OO.O#.#.O...O..#..#OO..O.............O.........O.#.......#OO#.O.#OOO.##OOO..OO#.....O#.O.#O.O##OO...
+.##...##O.....O..OO..O#.O.O.#....OOO.O.O#..#O#..#.O.OO...####O#......#.#O..O.O....#..O....#.#.#.O#.#
+.....#O..O.O.#......#..........#.OO...O.#O.O.....O.#OO.#.#.O#......OO..O.O.....#...O.O..OO...#O.O#..
+.O..#....#....OOO.O.#....O#O###....O.O#OO.............#...OOO.....#....O..O.......###............O..
+..#O.#....###..O...#.....OO#O.....#....###..O#.......#OO....O.O...#....#.O.O.#..O.##O...O..O#...##..
+O...O.#O.#O#....O.O#.......#............OO.....O.#O..O#O....O##O.OO..#..O..#O..O#O...##O.O.O.O#..O.#
+O#.O......#.......O....#...O.....#O#.#..O...O.###O.OO#.........O.....O..O...#.#O.....OO#..O.#...#...
+.#...O.......O.#.....O.......O.O..#....#..O#O.#..O.#..##.......##....O.#.....O........OO.O...O.....O
+..O..#.#O.O#...#.......#O#OO.#O....O...#O..O.O.#O.OO#......OO#....#...O.#...#O.#...O.#.OO#..O.#OO.O#
+.O.......O...#.......#....O..O......O.O.O#O.#O...O.#.....O..O...#OOO#..O...O##..OOO#....#..........O
+OO#..##O.O.O.O.#....O#.O#O.##..O......#.#.O.O..O.O...OO#.......#..O.#O.O#.OO....#O#O.O.O.#.O#O#.....
+#O#.O.......##OOO..OO...O#..#..O.O.##.O#....#OO....#...OO.#..#..O.......O#O.......#.O.O............O
+..O.OO.O#..OOO....OO.O...#.#.......#.O.......O..OOO.##.##.#...#.O.....O..O.......O.O.#..............
+OO#.....O.O.#.#...#.#.....O....#.#O..O......#..#..O...#.#....O#..OO....O.#.....O...O.#.O..#.........
+....O.#.O...O#....#.O.#.......O#.#.O##......#...O.#..O#..#.#O.O...#.....O......#O#.#.#O....O..O.O#.#
+.....###.O.O.O#.O.......O..OO#...#.#...#..O......#O....O...OOOO..O...#.#.#.#.O#..O.......OO.....#.#.
+...O.O...#O..O..#..O#.O....#O..#..O...#.O.O.OO....#O#O#.OOO##..#O..OOO#.O.O..O....#...O#..O...#O....
+.##.O...O..O.#.#OOO..O..O...O........#O.OO#..#OO......O....O.##...#..O#..O#...#..O.....O...##...O...
+.O.#.O#OO.#...O....#.O.O..OO.O#O...O#..##...O.O...#...O#OOO.....O.........O......#.O.#...........OO.
+O....O#O...#.OO#...#.........####..........O.#...#...O.O.O#.O..............##....O..O..O..#.#...##.#
+..O.OO.#.OO#..O.#O....O......O.............#...##...#.O..#..O###.#......O..##.O.........O.#........O
+O...#....#.......OO...O#O.......#.....#....OOO.#...OO.#O..O.#......#.##O....OO....O#.#.O..O...O..O..
+...#...#....O.#..OOOO#..O#..#.##O.#.#.O..#.O....OOO....#..#..#....OOO...#.O.O...#.#.#O.O..O.#..O....
+...O#.#...O.#.##O..O#..O.....OO#O...#.OO#..OO#O..OOO.O...#...O.#.O....O#...OOO..O...O....O....#.#..O
+#........#..O.###.#...O#.O#O.........##..O.O.#O.O.###O....##.#.#.#..O.#O....#OO#O.....O.........O.##
+O.O....#O.....O#...O#.....O##.OOO.#O.O..O....O..O...O....#...O.........O.#.O..#.#.O.O#O...#.#...O..O
+.O..O##.O........O.OOO#O...#....O.OOOO#O..O..............O..O.O.O...#..........#......O..O.O.#......
+.O....#OO#OO...#...O.##O.....#O.#.O.O...O.....OO#.O.......O#...#O..O#OOO.........##.....##...#...##O
+.O#..OO....OOO..#.......OOO...##....OO..O.O..........##...#.#...#....O..#....O..........#.#.#O#.#.O.
+##.......#O...O#.OO.#..O.O.O....#........#.O..........O.O.O..O.....#.OO#...#O#.O.OO..OO.O#..##....O.
+....#..#..#O.##O.#....#.#.OO.......##..O#.#.##......O.O.OO..##...O.#....#..O.#....#.O....#...#O..O..
+..O....#...OOO.#O..#..#...O..OOO..O#..#O......#..O...#.O..O.....#O...O#......#.......#O.O.........O#
+#.OO....O....###....#OOO..O.#..#........#OO.....#O..........#O...#..O.OO..#......##O..O##.........#.
+....#..O..........O.#.#..O.O.#....O..O....O..OO#....O.......OOO.....O.O.O..#....#.....O.O#.O#.##..O.
+#.O...OO..#....O.O..O...#O..O#.#O.#...O.....##..O...O##...O........#O..#O..O#.O.#.......O#.#...#.OO#
+.#.OOO#....#..O........OO....O#..###.O....O...O...O#.#O..#.OO........##..#..#...O..#.......OO...O#..
+.....OOO.#.O....O....#....O..O.O.O.O....O...#OO....#.OO#OO...O.OOOO.O...O.O....#OO...#O.#O..O....#..
+.#.#..........#O..OOO...#..O...#.............OO....#O...O#..O...#........O..#O#....OO.....OO##.O...#
+..OOO.OOO##.##O#...O.O..O......O#O..O##...##....O.#........O....##...O#O..O#.O...O.O...O....O.......
+..###.OO#..#.O.#....#..O..OO..O.###....O....#..O.O#.#......OO.....O#....O.OO....OO.O.O.O#........O..
+#O###.#......O......O......#...O#.O.O...O#OO.O#....O..#..O#.OO...O..O..#..#.#...#..##OO...OO....O..O
+..O...#..#O##O...#..#.#OO........O.#....O....................#...........#.....O..#...O#.#.O.O..#.#.
+O...#.O...#O..#..O.O.#.....O.#....O.O...##......#..#..OO...#..O..OOOOO..O..O...#..O.OO...O.O#O.#....
+........#...O.#.....O.O..O....#....#O......#..#........#O#.....#O##..OO.O...#......#OO.O#.O........O
+.O..##..O#....#....OO.#O.#O#OO#O.#..OOO#.......OO....O.#.....O....#..#..##...#O.....#....O..O....O..
+...##O..O.#.O..#.O.....#..O#.##OO#O#...O.##..#..#......O.##O.OO...O.#..#.O....#..O....O.O.........#.
+...O..O.#..O.#O#......O.#OO.O.##.##..O###.#.O........O..O..O#...#.O...O.....##....O.OO..#..O..#..O#.
+O....O......#..#O#.O....O...O.....#.O##O.O...#O.#O...O...#O...O.O#O...#O.#.#....#.#.#O....O.....OO..
+.O.##..###....OO................OOO.....#.#.OO.O...O#.OO.#..O........#...O.O#.O..O.O..O.O...O....O..
+...OOOO..O.#..O.#...O.##.O.O##.#..O.##..#.....##....O.O....O.O.##O.OO.#O.........#.##.O#...O.O..O...
+...O.O..#O.#..OO.#.#O#OO..#OO.O......O.O.OO....#..OO.......#O..O.##....O.O..##O#.#....OO.....#.O...#
+OO.....O....#O...O#.#..O...O#.#.O..#OO....O..#..OOO...O.........O....#.###O.OO....O....O............
+..O..O.....#O.#O#OO..##.O.........#..##.##.O..O#O#..O.O..O..O...###.....OO.......#.##..#O##..O#O..O.
+#O.#O...OOOO.O.###....#O..#O#O#.OO.....#O..#..#...O.#O.....#O....###.O....#..O...O..O....#......#...
+O##...#.....#..O.#.O.#.......#..O#.....#.O.O.#...O..O....OO.....#.O###.#.....OO....#OO..OOO..#......
+..O......#...#O..OO#O#OO....O.O.OOO.#O.OO.O......#....O##..O#.OO.##.#...O.##.....#...####.......##..
+.......OO#.O.O.#.O.......#O#........#O..##OO#.#O..##..OO.##OO....#..O......#..#.O..#...#.O.....OO...
+###.OO.O.O#..O.......#OO#.....#..O.O..O.O.......#..#O.##..#O..#..#...#O#......OO##O#OOO#...O#....O.#
+#O#.O.........#..O.#..#..#..............O..O..#..O##....O.##..O..O#..O.....#OO..O.#.......O....OO...
+#O#O....O#.#.O..O..#...#..#.#...#O.....O..##..#....O#.#.O.O.O...O.#...#.O....O#....#.....#.#..#...#O
+O...O........O.#..OOOO..#...O#O....##.O..#.......#..O..#..#O.#...OO..#.O..##..#...O#O.##.....#..#.O.
+O..#.##.......O..O......#..#.#.O...O#.O.......O#.O.O#O..#.O#.OOOOO.#OO.#.OO#....O....#...O####OO...#
+#O..O....O..#O..O.OO.#.O.##...#O#.....O...#.....#......##......O#O#.........#..#.O...O.O..........#.
+OOO.#.O.....O..OO.O#.#..#.#..#.............O#.......OOO#OO.O.#.#O...O.#..#...#..O...#.O#....O..O..##
+OO#........#.O.O....O#O...#O.#..#.#...#......##.......#..#..#.#.#.......O...##...O#...O..O.......O..
+O..#O......O....#O.O#..O........#......##..#...#O...OO....#.#...O........O.#O.......O.....O...#..O..
+..#O#.......O..O..O..........#...OO.#..OOO....O....#OOO#..O.....#.O#....O...#O.......#..#.O...#..##.
+...#O...O.OOO...O#.....#..#....##..#....#OO..O.OO#O.O#..#.O#O#O.....#OO#O...#.#O......O.....OO.....O
+..#...O.O.....O...O##O..O.....O..O..#O.O..O....O.#O....#O....O..O.O......O.....#..#....O......#.....
+O.#...O..#O.#...O.O.O..#..##...O.O..O#..O...O#....O........O#O.#O.#.O.......#.O.O..O.......OO.#.....
+O#...O.O#..#O#...............OO##.#..#...#O....O....#O.OO.O..O#.O.....#O.....O..O...#..#..#...#..O.O
+....OO.O#.#.......O..O.O.#..#.O#.O.....#............#....O..O..O..O.O..#..#..O.....#O.#O.#.O...O..#O
+.....#...OOO...#.O....O#...#.....O..OO....##O.OOO..#.O...#...O.##.O#O...O.....#.#...O...O.##.#.....O
+....##...O#O..O...##O.OOOO...#.#.....OOO..........O.O....O.#O.#..O#..O###...O....#.O#O......OOO..O.O
+#..#...OO##OOO.O#....#O#.O.....O#.#...##.#O..OO.#.#.O.O..OO.O#.........##.....O..O#..O......O.....##
+..O..OO.##O.##OO...O#.....#O.O..........#.#.......#..#..O....O...#......#..O.#.#...#.....#OO........
+O.......#O.....O....OO#.#..O.....OO..#..OOO.O....O##O#O.O....OO#......#.#.O......#.OO.O.#OO....#....
+....O...#.O....##.OO.....#O#.O...O....O#.O##.....O.#.O#........OO##...O..#.....O...O.....O...#..O#O.
+#.OO.#.O##....#..O....O..#...OO...#....#.##...OO....#O.........O..#......O.OO..#..#..##......#O...#.
+O...#.O.##..#.#OO#.O#.O###.O.#...O#..O###.......#....O.#.........O..O..#O#..O.O.O..OO..#.#...O#..O..
+......#..##..#..##...O#......#..#.#O#.....#.#.O...#.#O..#O..O.O.#..O.O.O....O....#....OO.#O......#.O
+..OO.##.#....O.O...O.#.....##O..#....#..OO#.#...##......#...OO...#.....#...#O..#O...#O......O#...O#.
+OOO.O##O...O..O.O#.##O#..OO.#.O..O...O.#O..O..#.#...O.O.......#O##.#..#.#.O.......O..OOO#.O....O#..O
+...O...OO.O...OO...O.....O#.#.#O.O.O.O..O..O...OO....O..###...##....#O....O...#.#.##....O....#O.O..#
+......#OO.........##.O...#..#.O.#..OO....O..O..O.#OO......OO.O#.......O...#..O.O#..OO.##.##.OOOOO...
+........O.....##..O.OO..O#.....O................O........OO#...##.....O#....#...#O.O..O...#.##..#O.O
+#OO.O.O.O.O#.OOO....#O#.#....#...#O#O.#.....OOO.....#.O..##.O##..O...........#......#...O.#.#.O.....
+.#O.........#.O.##O..#..O.O...OO..#..O.O#OO#..#O.O.O....#......O.....OO#..OO#.O.O..#.#.#OO.#..O.....
+...OO.O#O.O#.O.......O#..#OO.O.OO..O#.O.OO.O........O.OO..#..O...#.#.#....#.#.....OO.#.O..OO.....#..
+###.....O..#...OO.#OO........O....#O#OO...#.O...#.....#O...#.##..O..#O#..O##.O#.O.....#.O....#O...#.
+#O#.##......O....#.O##..#.......#.#..O......O.OOO.#....O##.#.O..OO...O..#...#.###......OO....O#.#.O#
+#OOOO#.#...OO..O..O..#..O..O...#OO.O.O.O#.#.##..#....####..O#....#O.OOO..O#O.#...O....#.O......O....
+.##OO....#......O..OOO......#..O.....#..O...O..#.#.........OO.O..##.......#.#O#.OO......O#O..O......
+........OOO.....OO........O.O.O.#O...#...O...O...O..O..#.....#O..#.#..OO....O...#..##..#O......O.#O#
diff --git a/day14/test b/day14/test
new file mode 100644
index 0000000..5a24dce
--- /dev/null
+++ b/day14/test
@@ -0,0 +1,10 @@
+O....#....
+O.OO#....#
+.....##...
+OO.#O....O
+.O.....O#.
+O.#..O.#.#
+..O..#O..O
+.......O..
+#....###..
+#OO..#....