Skip to content
Snippets Groups Projects
Commit 574093f8 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Added helper methods to convert data into common forms

parent 82c6c089
No related branches found
No related tags found
No related merge requests found
......@@ -252,5 +252,23 @@ Well... I'm going to take the part 2 code in a (very) slightly different directi
## Day 9
- [The problem](https://adventofcode.com/2022/day/9)
- [The solution](src/main/java/edu/unl/cse/bohn/year2022/Day9.java)
### Part 1
The subproblems are
- ...
### Part 2
...
### Refactoring
...
## Day 10
(coming soon)
......@@ -39,11 +39,7 @@ public class Day8 extends Puzzle {
}
private static int[][] getTreeHeights(List<String> data) {
int[][] treeHeights = new int[data.size()][data.get(0).length()];
for (int i = 0; i < treeHeights.length; i++) {
treeHeights[i] = data.get(i).chars().map(c -> c - '0').toArray();
}
return treeHeights;
return toIntMatrix(data);
}
private boolean[][] computeTreeVisibility(List<String> data) {
......
package edu.unl.cse.bohn;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public abstract class Puzzle {
......@@ -25,4 +27,19 @@ public abstract class Puzzle {
System.out.println("Part 1: " + computePart1(data));
System.out.println("Part 2: " + computePart2(data));
}
protected static List<Integer> toIntegerList(List<String> data) {
return data.stream().mapToInt(Integer::valueOf).boxed().toList();
}
protected static char[][] toCharMatrix(List<String> data) {
// I suspect this cast won't work
return (char[][]) data.stream().map(String::toCharArray).toArray();
}
protected static int[][] toIntMatrix(List<String> data) {
int[][] matrix = new int[data.size()][data.get(0).length()];
Arrays.setAll(matrix, i -> data.get(i).chars().map(c -> c - '0').toArray());
return matrix;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment