You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

namespace AdventOfCode._2021;
using System.Collections;
public class Day1
{
public void Part1()
{
var input = File.ReadAllLines("2021/input/day1.txt").AsInt();
int previous = input.First();
int count = 0;
foreach (var i in input)
{
if (i > previous)
{
count += 1;
}
previous = i;
}
Console.WriteLine(count);
}
public void Part2()
{
var input = File.ReadAllLines("2021/input/day1.txt").AsInt().ToList();
int previous = input[0] + input[1] + input[2];
int count = 0;
for (int i = 1; i < input.Count; i++)
{
if (i + 2 > input.Count - 1)
{
break;
}
int sum = input[i] + input[i + 1] + input[i + 2];
if (sum > previous)
{
count += 1;
}
previous = sum;
}
Console.WriteLine(count); // first input isn't counted.
}
}