From 747f6d92ab15e1c04d83156ec6358a08c995f183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kleszczy=C5=84ski?= Date: Tue, 12 Nov 2024 20:33:12 +0100 Subject: [PATCH] 2015 Day 19 part 2 --- 2015/d19/main.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/2015/d19/main.go b/2015/d19/main.go index 0b9b8aa..e9e0fc1 100644 --- a/2015/d19/main.go +++ b/2015/d19/main.go @@ -38,7 +38,24 @@ func part1(data TaskInput) int { } func part2(data TaskInput) int { - return -1 + // available substitutions: + // x => a b + // x => a Rn b Ar + // x => a Rn b Y c Ar + // x => a Rn b Y c Y d Ar + + molecule := strings.Join(data.Molecule, "") + + // Ar and Rn always are constant and appears at most one time in the substitutions, + // so we need one substitution for each occurence of Ar and Rn in final molecule + constantsCount := strings.Count(molecule, "Ar") + strings.Count(molecule, "Rn") + + // Y always comes with some value before, so we multiply by two, because we need to + // get Y as well as the glued part to the Y + variablesCount := 2 * strings.Count(molecule, "Y") + + // Sub 1 cause we are starting from "e", not from a blank canvas + return len(data.Molecule) - constantsCount - variablesCount - 1 } func main() {