-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp011.java
More file actions
32 lines (26 loc) · 788 Bytes
/
p011.java
File metadata and controls
32 lines (26 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package level01;
import org.junit.Test;
import data.Dir;
import lib.EulerTest;
public class p011 extends EulerTest {
final int N = 20;
final int K = 4;
/**
* Find the greatest product of K consecutive numbers in a NxN grid.
*/
@Test
public void test() {
long[][] grid = readAsGrid(" ");
for (int i : range(N))
for (int j : range(N))
for (Dir dir : Dir.ALL)
if (dir.inBounds(i, j, K - 1, N)) {
long prod = 1;
for (int k : range(K))
prod *= grid[i + k * dir.di][j + k * dir.dj];
if (prod > ans)
ans = prod;
}
check(70600674);
}
}