jwow22

AdventOfCode2021_Day1

Dec 2nd, 2021 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. public static int SolveP1(int[] data)
  2. {
  3.     int increases = 0;
  4.  
  5.     for (int i = 0; i < data.Length - 1; i++)
  6.     {
  7.         if (data[i + 1] > data[i])
  8.         {
  9.             increases++;
  10.         }
  11.     }
  12.     return increases;
  13. }
  14.  
  15. public static int SolveP2(int[] data)
  16. {
  17.     int[] arr = new int[data.Length];
  18.     for (int i = 0; i < data.Length - 1; i++)
  19.     {
  20.         for (int j = i; j < i + 3; j++)
  21.         {
  22.             if (j == data.Length) { return SolveP1(arr); }
  23.             arr[i] += data[j];
  24.         }
  25.     }
  26.     return -1;
  27. }
Add Comment
Please, Sign In to add comment