• 4 Posts
  • 237 Comments
Joined 1 year ago
cake
Cake day: July 3rd, 2023

help-circle














  • This was interesting! So iterating through the solution space would be infeasible here and it seems we need to look for boundaries between regions and follow them to find places where a solution could occur.

    Python: https://pastebin.com/8Ckx36fu

    • Make a list of places where location mappings are discontinuous (0, the end of each mapping, and the number before)
    • Repeat this for discontinuities in each intermediate layer
    • Trace each such location to its seed, and filter by seed ranges
    • Run the very minimal set of interesting seed numbers (around 2000 seeds) through the existing part1 algorithm




  • import re
    numbers = {
        "one" : 1,
        "two" : 2,
        "three" : 3,
        "four" : 4,
        "five" : 5,
        "six" : 6,
        "seven" : 7,
        "eight" : 8,
        "nine" : 9
        }
    for digit in range(10):
        numbers[str(digit)] = digit
    pattern = "(%s)" % "|".join(numbers.keys())
       
    re1 = re.compile(".*?" + pattern)
    re2 = re.compile(".*" + pattern)
    total = 0
    for line in open("input.txt"):
        m1 = re1.match(line)
        m2 = re2.match(line)
        num = (numbers[m1.group(1)] * 10) + numbers[m2.group(1)]
        total += num
    print(total)
    

    There weren’t any zeros in the training data I got - the text seems to suggest that “0” is allowed but “zero” isn’t.