From 1ac8cee3d5343f6cff3943dee38b428996c64546 Mon Sep 17 00:00:00 2001 From: Boxfriend Date: Tue, 2 Dec 2025 10:39:54 -0500 Subject: [PATCH] day two part two --- AdventOfCode2025/GiftShop.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AdventOfCode2025/GiftShop.cs b/AdventOfCode2025/GiftShop.cs index ba1cd4d..cc70962 100644 --- a/AdventOfCode2025/GiftShop.cs +++ b/AdventOfCode2025/GiftShop.cs @@ -4,22 +4,27 @@ namespace AdventOfCode2025; public class GiftShop : IAdventSolution { + private readonly Regex _regex = new(@"^(.+)\1+$"); + public AdventSolution Solve(string input) { var ranges = input.Split(',', StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); ulong totalInvalid = 0; + ulong newInvalid = 0; foreach (var rangeString in ranges) { var range = GetRange(rangeString); for (var i = range.Min; i <= range.Max; i++) { - if(IsInvalid(i)) - totalInvalid += (ulong)i; - + if (IsInvalid(i)) + totalInvalid += i; + + if(IsRepeat(i)) + newInvalid += i; } } - return new AdventSolution(totalInvalid.ToString(), null); + return new AdventSolution(totalInvalid.ToString(),newInvalid.ToString()); } private bool IsInvalid(ulong id) @@ -30,6 +35,8 @@ public class GiftShop : IAdventSolution var second = s[half..]; return first == second; } + + private bool IsRepeat(ulong id) => _regex.IsMatch(id.ToString()); private Range GetRange(string input) {