Advertisement
MBrendecke

MusterAddierer

May 16th, 2020
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.52 KB | None | 0 0
  1. /*
  2. * Version 1.1
  3. * Datum: 16.05.2020
  4. * Uhrzeit: 21:29
  5. */
  6.  
  7. package exp.sandbox;
  8.  
  9. public class Main {
  10.     public static void main(String[] args) {
  11.         long sum = getSum(getData(), getMuster(), getDeltas());
  12.         System.out.println(sum);
  13.     }
  14.  
  15.     private static long[][] getData() {
  16.         return new long[][]{
  17.                 {1, 1, 1, 1, 1},
  18.                 {1, 1, 3, 1, 5, 1},
  19.                 {1, 2, 1, 4, 1, 6},
  20.                 {1, 1, 1, 1, 1},
  21.                 {1, 1, 1}
  22.         };
  23.     }
  24.  
  25.     private static int[][] getMuster() {
  26.         return new int[][]{
  27.                 {1, 2},
  28.                 {0, 3},
  29.                 {0, 3},
  30.                 {1, 2}
  31.         };
  32.     }
  33.  
  34.     private static int[][] getDeltas() {
  35.         return new int[][]{
  36.                 {0, 0},
  37.                 {0, 1},
  38.                 {0, 2},
  39.                 {1, 0}
  40.         };
  41.     }
  42.  
  43.     private static long getSum(long[][] data, int[][] muster, int dy, int dx) throws IndexOutOfBoundsException {
  44.         long sum = 0;
  45.  
  46.         for (int my = 0; my < muster.length; my++) {
  47.             for (int mx = 0; mx < muster[my].length; mx++) {
  48.                 sum += data[my + dy][muster[my][mx] + dx];
  49.             }
  50.         }
  51.  
  52.         return sum;
  53.     }
  54.  
  55.     private static long getSum(long[][] data, int[][] muster, int[][] deltas) throws IndexOutOfBoundsException {
  56.         long sum = 0;
  57.  
  58.         for (var delta : deltas) {
  59.             sum += getSum(data, muster, delta[0], delta[1]);
  60.         }
  61.  
  62.         return sum;
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement