Reducing Leibniz perl code in characters
Perl 53 bytes
You can save two more strokes:
<>;print${\map$a-=(-1)**$_/(2*$_-1),1..$_},$a=$/for<>
Perl 55 bytes
<>;map($s-=(-1)**$_/(2*$_-1),1..$_),$s=!print$s,$/for<>
Without using any Perl non-standard features (such as say
). 3 bytes are wasted removing the first value from the input.
Sample usage:
in.dat
2
10
20
$ perl leibniz.pl < in.dat
0.760459904732351
0.77290595166696
Alternative, also 55 bytes
map{$s-=(-1)**$_/($_*2-1)for 1..<>;$s=!print$s,$/}1..<>
The alternative may be run interactively, without requiring an input file. Which, as I understand, is what you meant by running indefinitely.