Advertisement
Guest User

Untitled

a guest
Dec 14th, 2022
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.50 KB | None | 0 0
  1. namespace AoC2022;
  2.  
  3. internal class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         Day1();
  8.         Console.WriteLine("\nready");
  9.         Console.Read();
  10.     }
  11.  
  12.     static void Day1()
  13.     {
  14.         List<int> cal = new();
  15.         int i = 0;
  16.  
  17.         foreach (var line in File.ReadLines("input_1.txt"))
  18.         {
  19.             if (int.TryParse(line, out var n))
  20.                 i += n;
  21.             else
  22.             {
  23.                 cal.Add(i);
  24.                 i = 0;
  25.             }
  26.         }
  27.  
  28.         cal.Sort();
  29.         Console.WriteLine(cal.Max()); //part 1
  30.         Console.WriteLine(cal.TakeLast(3).Sum()); //part 2
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement