Post History
JavaScript (Node.js), 47 bytes f=(a,b=0,c=a=>a&&1/a+c(a-1))=>c(b)<a?f(a,b+1):b Try it online! For large numbers, a rounding error will occur and yield incorrect result. The ...
Answer
#1: Initial revision
# [JavaScript (Node.js)], 47 bytes <!-- language-all: lang-javascript --> f=(a,b=0,c=a=>a&&1/a+c(a-1))=>c(b)<a?f(a,b+1):b [Try it online!][TIO-khjfo979] [JavaScript (Node.js)]: https://nodejs.org [TIO-khjfo979]: https://tio.run/##bcpLDkAwEADQvYPINL712WA4y3SoEGkFcf1iK92@vJVuOvlY9isxdpyc0wgUK8xjRsKewlBmFDFQIoXAnkGJjgb9nUiKRrmWrTntNqWbnUHDu9rgZ4XHSo9VHqtfcw8 "JavaScript (Node.js) – Try It Online" For large numbers, a rounding error will occur and yield incorrect result. The solution below works for any integer (no rounding errors): # 93 bytes <!-- language-all: lang-javascript --> f=(a,i=0n,p=a=>g(a)/c(a),g=(a,b=a)=>a&&c(b)/a+g(~-a,b),c=a=>a?a*c(~-a):1n)=>p(i)<a?f(a,-~i):i [Try it online!][TIO-khjfrvbo] [JavaScript (Node.js)]: https://nodejs.org [TIO-khjfrvbo]: https://tio.run/##fctNDoMgEIbhfQ9iZlqo/d1o0UP0BCMVMo0BoqZLr06h64bNLL7nnTd9aNEzh1U6/xpjNApIsDo5ERSpzgJhrdMRNsOgCFVHVaVhwJoOFjaZVhQ6x9TTXucFm7NLXQDGB/UmPcqNseHYau8WP43HyVt4rjM7CwZSjNju/uOlhNcS3kp4/2H8Ag "JavaScript (Node.js) – Try It Online"