using Printf """ calc precision backwards from answer """ function calcprecision(value::BigFloat) max(exponent(value) + 16, 64) # 16 digit = margin, 64 digit = minimum precision end # initial value of a[0] a0 = 0 const DIR = "./csv" fpath_old = "" # mkdir mkpath(DIR) # loop of a0 while true global a0, fpath_old a0 += 1 # output file name million = div(a0, 1000000) * 1000000 fpath = @sprintf("%s/%d-%d.csv", DIR, million, million + 1000000 - 1) if fpath != fpath_old open(fpath, "w") do f # header println(f, "a[0],steps to reach 1,argmax,max-term") end fpath_old = fpath end # initial values a_k = BigFloat(a0) amax = a_k kmax = 0 k = 0 # initial precision precision = calcprecision( a_k ) setprecision(precision) # loop of k while a_k > 1 k += 1 while true # odd if mod(a_k,2) == 0 a_kpp = floor( sqrt(a_k) ) # even else a_kpp = floor( a_k * sqrt(a_k) ) #a_kpp = floor( a_k^(1.5)) end # increase precision and retry if calcprecision( a_kpp ) > precision renewprecision = true retry = true # decrease precision elseif calcprecision( a_kpp ) < precision / 10 renewprecision = true retry = false # keep else renewprecision = false retry = false end # setprecision if renewprecision precision = calcprecision( a_kpp ) setprecision(precision) end # break if ! retry a_k = a_kpp break end end # update max-term if a_k > amax amax = a_k kmax = k end end # output open(fpath, "a") do f # less than 100 digit -> write as integer if exponent(amax) * log10(2) <= 100 @printf(f, "%d,%d,%d,%d\n", a0, k, kmax, amax) # write as float else @printf(f, "%d,%d,%d,%.5e\n", a0, k, kmax, amax) end end end