Skip to content

Commit baf6d9e

Browse files
committed
2019.24.1 calc biodiversity for demo content
1 parent 393dc3e commit baf6d9e

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

java/src/main/java/y2019/d24/Part1.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,30 @@ public static void main(String[] args) {
4343
}
4444

4545
mapString = mapToString(newMap);
46+
map = newMap;
4647

4748
if (!seen.add(mapString)) {
4849
break;
4950
}
5051
//System.out.println(mapString);
51-
map = newMap;
5252
}
5353

5454
System.out.println(mapString);
55+
System.out.println(biodiversityRating(map));
56+
}
57+
58+
private static int biodiversityRating(boolean[][] inMap) {
59+
int exponent = -1;
60+
int biodiversityRating = 0;
61+
for (boolean[] line: inMap) {
62+
for (boolean field: line) {
63+
exponent++;
64+
if (field) {
65+
biodiversityRating += Math.pow(2, exponent);
66+
}
67+
}
68+
}
69+
return biodiversityRating;
5570
}
5671

5772
private static boolean willLive(int x, int y) {

0 commit comments

Comments
 (0)