Created
March 2, 2017 21:59
-
-
Save aidancbrady/93e45d791e95ec7e3604b6487ccdbf60 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<int[][]> interpret(String path) { | |
List<int[][]> ret = new ArrayList<>(); | |
try { | |
File file = new File(path); | |
BufferedReader reader = new BufferedReader(new FileReader(file)); | |
String s; | |
while((s = reader.readLine()) != null) { | |
s = s.trim(); | |
if (!s.isEmpty()) { | |
int maxSize = (int)Math.sqrt(s.length()); | |
int[][] grid = new int[maxSize][maxSize]; | |
for(int i = 0; i < s.length(); i++) { | |
char c = s.charAt(i); | |
int val = c == '.' ? 0 : Integer.parseInt(Character.toString(c)); | |
grid[i/maxSize][i%maxSize] = val; | |
} | |
ret.add(grid); | |
} | |
} | |
reader.close(); | |
} catch(Exception e) { | |
e.printStackTrace(); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment