Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Version 1.1
- * Datum: 16.05.2020
- * Uhrzeit: 21:29
- */
- package exp.sandbox;
- public class Main {
- public static void main(String[] args) {
- long sum = getSum(getData(), getMuster(), getDeltas());
- System.out.println(sum);
- }
- private static long[][] getData() {
- return new long[][]{
- {1, 1, 1, 1, 1},
- {1, 1, 3, 1, 5, 1},
- {1, 2, 1, 4, 1, 6},
- {1, 1, 1, 1, 1},
- {1, 1, 1}
- };
- }
- private static int[][] getMuster() {
- return new int[][]{
- {1, 2},
- {0, 3},
- {0, 3},
- {1, 2}
- };
- }
- private static int[][] getDeltas() {
- return new int[][]{
- {0, 0},
- {0, 1},
- {0, 2},
- {1, 0}
- };
- }
- private static long getSum(long[][] data, int[][] muster, int dy, int dx) throws IndexOutOfBoundsException {
- long sum = 0;
- for (int my = 0; my < muster.length; my++) {
- for (int mx = 0; mx < muster[my].length; mx++) {
- sum += data[my + dy][muster[my][mx] + dx];
- }
- }
- return sum;
- }
- private static long getSum(long[][] data, int[][] muster, int[][] deltas) throws IndexOutOfBoundsException {
- long sum = 0;
- for (var delta : deltas) {
- sum += getSum(data, muster, delta[0], delta[1]);
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement