4 ms·
let y=3n*(10n**1000020n); const f=(i,x,p)=>{(x>0)?f(i+2n,x*i/((i+1n)*4n),p+x/(i+2n)):p/(10n**20n)} console.log(f(1n,y/8n,y)); Not sure if I can golf it an
by foxes 7y ago
let y=3n*(10n**1000020n);
const f=(i,x,p)=>{(x>0)?f(i+2n,x*i/((i+1n)*4n),p+x/(i+2n)):p/(10n**20n)}
console.log(f(1n,y/8n,y));
Not sure if I can golf it anymore
- minitech 7y agoThat version already doesn’t work… once you fix the arrow function, there’s also the issue that most engines today don’t support proper tail calls, so nothing recursive will be portable. (But if it did, you could save a lot of characters by dropping unnecessary parentheses, expanding (i+1n)×4n to 4n×i+4n, replacing the const with a comma, removing semicolons…)
- sqnguyen 7y agothis is my perl golf version of the same series. You can probably can do something similar with js: map$l+=(-1)$_/(1-$_2)4,1..<>;die$l
- NieDzejkob 7y agoDoesn't work for me [0]. Perhaps HN messed it up somehow? [0]: https://tio.run/##K0gtyjH9/z83sUAlR9tWQ9dQUyVeX8NQVyXeSNNEx1BPz8bOOiUzVSXn/38A https://tio.run/##K0gtyjH9/z83sUAlR9tWQ9dQUyVeX8NQVyXeSNNEx1...
- sqnguyen 7y agoI guess so... https://tio.run/##K0gtyjH9/z83sUAlR9tWQ9dQU0tLJV5fw1BXJV7LSFPLRMdQT8/GzjolM1UlR@H/f0MDIAAA https://tio.run/##K0gtyjH9/z83sUAlR9tWQ9dQU0tLJV5fw1BXJV7LSF...
- mkl 7y agoTo post code, indent it with two spaces, or HN will turn asterisks into italics on/off.