Completed day 6
This commit is contained in:
parent
9cf58332cf
commit
f1e645baa0
@ -7,9 +7,9 @@ InputReader inputReader = new()
|
|||||||
//IsDebug = true
|
//IsDebug = true
|
||||||
};
|
};
|
||||||
|
|
||||||
//inputReader.SetInputByChallange(3);
|
inputReader.SetInputByChallange(6);
|
||||||
|
|
||||||
IChallange challange = new Day08(inputReader);
|
IChallange challange = new Day06(inputReader);
|
||||||
|
|
||||||
Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}");
|
Console.WriteLine($"Part 1: {await challange.GetSolutionPart1()}");
|
||||||
|
|
||||||
|
|||||||
@ -1,19 +1,63 @@
|
|||||||
using AdventOfCode.Core;
|
using AdventOfCode.Core;
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace AdventOfCode.Solutions._2023
|
namespace AdventOfCode.Solutions._2023
|
||||||
{
|
{
|
||||||
public class Day06(InputReader reader) : IChallange
|
public partial class Day06(InputReader reader) : IChallange
|
||||||
{
|
{
|
||||||
private InputReader _inputReader = reader;
|
private InputReader _inputReader = reader;
|
||||||
|
|
||||||
public async Task<string> GetSolutionPart1()
|
public async Task<string> GetSolutionPart1()
|
||||||
{
|
{
|
||||||
return string.Empty;
|
var data = (await _inputReader.ReadAsArrayString()).Select(line => GetDigets().Matches(line)).ToArray();
|
||||||
|
long totalValue = 1;
|
||||||
|
for (int index = 0; index < data[0].Count; index++)
|
||||||
|
{
|
||||||
|
totalValue *= CalculateWays(int.Parse(data[0][index].Value), int.Parse(data[1][index].Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalValue.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetSolutionPart2()
|
public async Task<string> GetSolutionPart2()
|
||||||
{
|
{
|
||||||
return string.Empty;
|
var data = (await _inputReader.ReadAsArrayString()).Select(line => GetDigets().Matches(line.Replace(" ", string.Empty))).ToArray();
|
||||||
|
return CalculateWays(long.Parse(data[0][0].Value), long.Parse(data[1][0].Value)).ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long CalculateWays(long raceTime, long currentDistance)
|
||||||
|
{
|
||||||
|
long distance,
|
||||||
|
waysToWin = 0,
|
||||||
|
time = raceTime;
|
||||||
|
if (raceTime % 2 == 1)
|
||||||
|
{
|
||||||
|
// uneven
|
||||||
|
time = (time + 1) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
time /= 2;
|
||||||
|
time++;
|
||||||
|
waysToWin++;
|
||||||
|
}
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
distance = time * (raceTime - time);
|
||||||
|
if (distance > currentDistance)
|
||||||
|
waysToWin += 2;
|
||||||
|
|
||||||
|
time++;
|
||||||
|
}
|
||||||
|
while (distance > currentDistance);
|
||||||
|
|
||||||
|
return waysToWin;
|
||||||
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex(@"\d+")]
|
||||||
|
private static partial Regex GetDigets();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,12 +34,8 @@ namespace AdventOfCode.Solutions._2023
|
|||||||
{
|
{
|
||||||
public int Bid { get; set; }
|
public int Bid { get; set; }
|
||||||
public SetRanks Rank { get; set; }
|
public SetRanks Rank { get; set; }
|
||||||
public int HighValue { get; set; }
|
|
||||||
|
|
||||||
public string Source { get; set; }
|
public string Source { get; set; }
|
||||||
|
|
||||||
public string JokerSource { get; set; } = string.Empty;
|
public string JokerSource { get; set; } = string.Empty;
|
||||||
|
|
||||||
public List<char> CharCompairList => string.IsNullOrEmpty(JokerSource) ? CardValues : CardValuesJoker;
|
public List<char> CharCompairList => string.IsNullOrEmpty(JokerSource) ? CardValues : CardValuesJoker;
|
||||||
|
|
||||||
public Hand(string line, bool jokerMode = false)
|
public Hand(string line, bool jokerMode = false)
|
||||||
|
|||||||
@ -1,10 +1,2 @@
|
|||||||
LR
|
Time: 7 15 30
|
||||||
|
Distance: 9 40 200
|
||||||
11A = (11B, XXX)
|
|
||||||
11B = (XXX, 11Z)
|
|
||||||
11Z = (11B, XXX)
|
|
||||||
22A = (22B, XXX)
|
|
||||||
22B = (22C, 22C)
|
|
||||||
22C = (22Z, 22Z)
|
|
||||||
22Z = (22B, 22B)
|
|
||||||
XXX = (XXX, XXX)
|
|
||||||
Loading…
Reference in New Issue
Block a user