@@ -0,0 +1,1981 @@
+import java.util.ArrayDeque;%0Aimport java.util.Iterator;%0Aimport java.util.stream.Collectors;%0A%0Aclass AoC_2018_05 extends Solution %7B%0A    static final int DAY = 5;%0A    static final String TITLE = %22Advent of Code 2018 Day 5: Alchemical Reduction%22;%0A%0A    public static void main(String%5B%5D args) %7B%0A        System.out.println(TITLE);%0A%0A        // Tests%0A        testStringsShouldEliminate();%0A        testReducePolymer();%0A%0A        // Solve%0A        String puzzleInput = loadPuzzleInputLines(DAY).collect(Collectors.joining());%0A        int partOneResult = solvePartOne(puzzleInput);%0A        assert partOneResult == 11546;%0A        System.out.printf(%22Part one: %25d%5Cn%22, partOneResult);%0A    %7D%0A%0A    static int solvePartOne(String puzzleInput) %7B%0A        return reducePolymer(puzzleInput).length();%0A    %7D%0A%0A    static String reducePolymer(String polymer) %7B%0A        ArrayDeque%3CString%3E stack = new ArrayDeque%3C%3E(polymer.length());%0A        for (String c : polymer.split(%22%22)) %7B%0A            String stackTop = stack.peekLast();%0A            if (stackTop != null && stringsShouldEliminate(c, stackTop)) %7B%0A                stack.removeLast();%0A            %7D else %7B%0A                stack.add(c);%0A            %7D%0A        %7D%0A        StringBuilder builder = new StringBuilder();%0A        for (String c : stack) %7B%0A            builder.append(c);%0A        %7D%0A        return builder.toString();%0A    %7D%0A%0A    static boolean stringsShouldEliminate(String first, String second) %7B%0A        return first.equalsIgnoreCase(second) && !first.equals(second);%0A    %7D%0A%0A    static void testReducePolymer() %7B%0A        String input = %22dabAcCaCBAcCcaDA%22;%0A        String expected = %22dabCBAcaDA%22;%0A        String result = reducePolymer(input);%0A        assert result.equals(expected) : result;%0A    %7D%0A%0A    static void testStringsShouldEliminate() %7B%0A        assert stringsShouldEliminate(%22a%22, %22A%22);%0A        assert !stringsShouldEliminate(%22a%22, %22a%22);%0A        assert stringsShouldEliminate(%22C%22, %22c%22);%0A        assert !stringsShouldEliminate(%22C%22, %22C%22);%0A    %7D%0A%0A%7D%0A

Solve part one