using System; using System.Collections.Generic; using System.IO; using System.Linq; public class Day1 { public static void PartA() { /* * Mind the sloppyness of not checking for i, j, k being the same number with the same index in nums! Just wanted to see if this approach was enough and it worked so I never refined it. */ //DAY 1! string path = Directory.GetCurrentDirectory() + "input.txt"; List nums = new List(); using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { nums.Add(Int32.Parse(sr.ReadLine())); } } foreach (int i in nums) { foreach (int j in nums) { if (i + j == 2020) { Console.WriteLine(i * j); return; } } } } static void PartB() { //DAY 1! string path = Directory.GetCurrentDirectory() + "/input.txt"; List nums = new List(); using (StreamReader sr = new StreamReader(path)) { while (sr.Peek() >= 0) { nums.Add(Int32.Parse(sr.ReadLine())); } } foreach (int i in nums) { foreach (int j in nums) { foreach (int k in nums) { if (i + j + k == 2020) { Console.WriteLine(i * j * k); return; } } } } } }