feature(day4): added day4 solution
parent
9d041d261d
commit
af63a460a7
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,31 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace AOC2022.Puzzles;
|
||||
|
||||
public class Day4 : IPuzzle
|
||||
{
|
||||
private readonly IEnumerable<int[][]> _parsedData;
|
||||
|
||||
public Day4(IEnumerable<string> linesFromFile)
|
||||
{
|
||||
_parsedData = linesFromFile
|
||||
.Select(line => line.Trim().Split(",")
|
||||
.Select(assignments => assignments.Split("-")
|
||||
.Select(range => Convert.ToInt32(range))
|
||||
.ToArray())
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
public void SolveFirstPuzzle()
|
||||
{
|
||||
var fullOverlapCount = _parsedData.Count(asns =>
|
||||
(asns[0][0] <= asns[1][0] && asns[0][1] >= asns[1][1]) || (asns[0][0] >= asns[1][0] && asns[0][1] <= asns[1][1]));
|
||||
Console.WriteLine($"Assignment Pairs with Full overlap : {fullOverlapCount}");
|
||||
}
|
||||
|
||||
public void SolveSecondPuzzle()
|
||||
{
|
||||
var partialOverlapCount = _parsedData.Count(asns => asns[0][0] <= asns[1][1] && asns[0][1] >= asns[1][0]);
|
||||
Console.WriteLine($"Assignment Pairs with any overlap : {partialOverlapCount}");
|
||||
}
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=asns/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=borgers/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Shieeeeeeeetttt/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
Loading…
Reference in New Issue