-
Notifications
You must be signed in to change notification settings - Fork 0
/
DayOne.cs
58 lines (52 loc) · 2.04 KB
/
DayOne.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace advent_of_code_2020
{
class DayOne
{
/*static void Main(string[] args)
{
string[] lines = System.IO.File.ReadAllLines(@"C:\Users\domin\source\repos\advent-of-code-2020\inputs\day1.txt");
List<string> stringList = new List<string>(lines);
checkingTwoNumbersSumsTo2020(stringList);
checkingThreeNumbersSumsTo2020(stringList);
}
*/
public static void checkingTwoNumbersSumsTo2020(List<string> array)
{
array.ForEach(number =>
{
var intNumber = Int32.Parse(number);
Debug.WriteLine("Checking " + number);
int searchedNumber = 2020 - intNumber;
if (array.Contains(searchedNumber.ToString()))
{
Debug.WriteLine("***** [" + number + "] *****");
var multiple = intNumber * searchedNumber;
Debug.WriteLine("***** [" + number + "]*[" + searchedNumber + "]=[" + multiple + "] *****");
}
});
}
public static void checkingThreeNumbersSumsTo2020(List<string> array)
{
array.ForEach(numberOne =>
{
var firstNumber = Int32.Parse(numberOne);
Debug.WriteLine("***** [" + numberOne + "] *****");
var searchedSum = 2020 - firstNumber;
array.ForEach(numberTwo =>
{
var secondNumber = Int32.Parse(numberTwo);
int thirdNumber = searchedSum - secondNumber;
if (array.Contains(thirdNumber.ToString()))
{
var multiple = firstNumber * secondNumber * thirdNumber;
Debug.WriteLine("***** [" + firstNumber + "]*[" + secondNumber + "]*[" + thirdNumber + "]=[" + multiple + "] *****");
}
});
}
);
}
}
}