diff --git a/day-24/internal/one/solve.go b/day-24/internal/one/solve.go index b0b7847..5ed5883 100644 --- a/day-24/internal/one/solve.go +++ b/day-24/internal/one/solve.go @@ -2,42 +2,28 @@ package one import ( "bytes" - "cmp" - "slices" + "sort" "strconv" "strings" - - log "github.com/sirupsen/logrus" ) func Solve(buf []byte) (int, error) { r := bytes.NewReader(buf) - initial, wires, expressions, err := parseLines(r) + wires, expressions, err := parseLines(r) if err != nil { return 0, err } - for k, v := range initial { - wires[k] = v - } - wires = calculateWire(expressions, wires) - - zWires := []zWire{} - for k, v := range wires { - if strings.HasPrefix(k, "z") { - zWires = append(zWires, zWire{k, v}) - } - } - slices.SortFunc(zWires, func(a, b zWire) int { - return cmp.Compare(b.name, a.name) + zWires := filter(wires, func(name string) bool { + return strings.HasPrefix(name, "z") }) + sort.Sort(byName(zWires)) var binStr strings.Builder for _, zWire := range zWires { - binStr.WriteString(strconv.FormatInt(int64(zWire.value), 2)) + binStr.WriteString(strconv.Itoa(zWire.value)) } - log.Debug(binStr.String()) return mustConvBinToDec(binStr.String()), nil }