You are viewing a single comment's thread. Return to all comments →
I tried really really hard to make this code work but it doesn't. It passes only two or three test cases and fails all the rest.
MAX_MOVES = 100 def downToZero(n, moves=0, absolute_path=[], max_moves=MAX_MOVES): attemptives = [] division_path = [] while n > 0: ab = [] if n >= 4: max_divisor = n / 2 m = 2 while m <= max_divisor: if n % m == 0: ab.append((m, n / m)) max_divisor = int(n / m) m += 1 if ab: division_path.append([n, moves, [n for n in absolute_path]]) n = min(map(max, ab)) absolute_path.append(1) moves += 1 continue absolute_path.append(2) moves += 1 n -= 1 attemptives.append([moves, absolute_path]) if moves <= max_moves: for path in division_path: attemptives.append( downToZero(path[0] - 1, path[1] + 1, path[2] + [1], moves) ) result = sorted(attemptives, key=lambda x: x[0])[0] if max_moves == MAX_MOVES: return result[0] return result
Seems like cookies are disabled on this browser, please enable them to open this website
Down to Zero II
You are viewing a single comment's thread. Return to all comments →
I tried really really hard to make this code work but it doesn't. It passes only two or three test cases and fails all the rest.