Skip to content

Commit

Permalink
day 11 part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaKateryna committed Dec 11, 2024
1 parent 4ae1d29 commit 09a1a93
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions AdventOfCode/Day11.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

namespace AdventOfCode;

public class Day11 : BaseDay
{
public override ValueTask<string> Solve_1()
{
List<Stone> stones = GetInput();

for (int i = 0; i < 25; ++i)
{
Blink(stones);
}

return new(stones.Count.ToString());
}

public override ValueTask<string> Solve_2()
{
return new("");
}

private void Blink(List<Stone> stones)
{
for (int i = 0; i < stones.Count; i++)
{
if (stones[i].Value == 0)
{
stones[i].Value++;
}
else if (stones[i].Value.ToString().Length % 2 == 0)
{
string stoneNumberString = stones[i].Value.ToString();
long one = long.Parse(stoneNumberString.Substring(0, stoneNumberString.Length / 2));
long two = long.Parse(stoneNumberString.Substring(stoneNumberString.Length / 2));

stones[i].Value = one;
stones.Insert(i + 1, new Stone(two));
i++;
}
else
{
stones[i].Value *= 2024;
}
}
}

private List<Stone> GetInput()
{
return File.ReadAllText(InputFilePath)
.Split(" ", StringSplitOptions.RemoveEmptyEntries)
.Select(x => new Stone(long.Parse(x)))
.ToList();
}

private class Stone(long Value)
{
public long Value { get; set; } = Value;
}
}

0 comments on commit 09a1a93

Please sign in to comment.