-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Text; | ||
|
||
namespace AdventOfCode.Solutions._2018; | ||
|
||
/// <summary> | ||
/// Day 05: Alchemical Reduction | ||
/// https://adventofcode.com/2018/day/05 | ||
/// </summary> | ||
[Description("Alchemical Reduction")] | ||
public sealed partial class Day05 { | ||
private const int OFFSET = 'a' - 'A'; | ||
|
||
public static string Part1(string[] input, params object[]? _) => Solution1(input).ToString(); | ||
public static string Part2(string[] input, params object[]? _) => Solution2(input).ToString(); | ||
|
||
private static int Solution1(string[] input) { | ||
string polymer = input[0]; | ||
|
||
int currentLength; | ||
do { | ||
StringBuilder newPolymer = new(); | ||
currentLength = polymer.Length; | ||
for (int i = 0; i < polymer.Length; i++) { | ||
if (i < polymer.Length - 1 && (polymer[i] + OFFSET == polymer[i + 1] || polymer[i] == polymer[i + 1] + OFFSET)) { | ||
i++; | ||
} else { | ||
_ = newPolymer.Append(polymer[i]); | ||
} | ||
} | ||
polymer = newPolymer.ToString(); | ||
} while (polymer.Length != 0 && polymer.Length != currentLength); | ||
|
||
return polymer.Length; | ||
} | ||
|
||
private static string Solution2(string[] input) { | ||
//string inputLine = input[0]; | ||
//List<string> inputs = input.ToList(); | ||
return "** Solution not written yet **"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace AdventOfCode.Tests.Year2018; | ||
|
||
public class Tests_05_Alchemical_Reaction | ||
{ | ||
const int DAY = 5; | ||
|
||
[Theory] | ||
[InlineData("aA", 0)] | ||
[InlineData("abBA", 0)] | ||
[InlineData("abAB", 4)] | ||
[InlineData("aabAAB", 6)] | ||
[InlineData("dabAcCaCBAcCcaDA", 10)] | ||
public void Part1(string input, int expected) | ||
{ | ||
_ = int.TryParse(SolutionRouter.SolveProblem(YEAR, DAY, PART1, input), out int actual); | ||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[Theory] | ||
[InlineData("aA", 9999)] | ||
public void Part2(string input, int expected) | ||
{ | ||
_ = int.TryParse(SolutionRouter.SolveProblem(YEAR, DAY, PART2, input), out int actual); | ||
Assert.Equal(expected, actual); | ||
} | ||
} |