Speed up search for the smallest x such that f(x) = target
问题 Problem Given n , find the smallest positive x such that f(x) = n . f(x) is the sum of the digit sum of the factorials of the digits of x . For example, f(15) = digit_sum(1!) + digit_sum(5!) = digit_sum(1) + digit_sum(120) = (1) + (1 + 2 + 0) = 4 Breath first search can find the answer. Are there faster ways? Breath First Search def bfs(target, d_map): # Track which values of f(x) have we visited visited = set([0]) # f(x) of the current level of the search tree todo = [0] # Digits of x for