Improving the algorithm there was a question about the behavior of the interpreter. It shuts up without messages and reboots. Here is an intermediate print code that you can skip for now. The essence of the issue in the texts:
import time import sys import functools from math import sqrt #print(f' sys.getrecursionlimit()={sys.getrecursionlimit()}') i=0 sys.setrecursionlimit(10000) @functools.lru_cache() def f(x): global i i +=1 if i%250==0: print(i) if x <=1: return 0 return 1 + min([ f(m + x // m - 2) for m in range(1,int(sqrt(x))+1) if x%m==0]) x = int(input("дай целое!")) t0 = time.clock() print( f(x)) t1 = time.clock() print (t1-t0, ' i=', i) here's what is strange: when you type for example 1024, it completely works out and produces the following:
дай целое!1024 250 500 750 ... 3250 3500 7 0.12052656332407201 i= 3636 that is, answer 7 is obtained in 3636 iterations in 0.12 seconds, and when you enter the number 1040, it shuts up without the words “on 1000+ recursions!?!
дай целое!1040 250 500 750 1000 =============================== RESTART: Shell =============================== In this regard, two questions
1) why so
2) how to test / debug recursive functions in general in the absence of at least some message from the interpreter?
Insulting addition: but in MS VS Python - where GIL is disabled - the algorithm works "through time". That is, a “clean” Python ALWAYS shuts up on the number 1040, and the same Python from MS VS 2017 - it gives the result, and then it “hangs” on the same 1000+ recursions. How is this possible and how to overcome, if it then believes that it does not count and hangs without words?
