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.

81 lines
2.3 KiB

using AdventOfCode.Contracts;
using AoC.Utils;
using System;
using System.Diagnostics;
namespace AoC.TwentyTwenty
{
namespace AoC.TwentyTwenty
{
class Two : Day
{
public override int Year => 2020;
public override int DayNumber => 2;
public override void BigBoi(string[] input)
{
throw new NotImplementedException();
}
public override void Part1(string[] input)
{
int total = 0;
foreach (string s in input)
{
int occurences = 0;
string[] split = s.Split(" ");
string[] startEnd = split[0].Split("-");
int start = int.Parse(startEnd[0]);
int end = int.Parse(startEnd[1]);
char c = split[1][0];
foreach (char letter in split[2])
{
if (letter == c)
{
occurences += 1;
}
}
if (occurences >= start && occurences <= end)
{
total += 1;
}
}
Print("1", total);
}
public override void Part2(string[] input)
{
int total = 0;
foreach (string s in input)
{
string[] split = s.Split(" ");
string[] startEnd = split[0].Split("-");
string password = split[2];
char start = password[int.Parse(startEnd[0]) - 1];
char end = password[int.Parse(startEnd[1]) - 1];
char c = split[1][0];
bool thing = (start, end) switch
{
_ when start == end => false,
_ when start == c || end == c => true,
_ => false
};
if (thing)
{
total += 1;
}
}
Print("2", total);
}
}
}
}