Calculate the value of \$\zeta(s)\$

Mathematica, 9 7 11 bytes

Zeta@#~N~6&

Explanation:

Zeta@#       (* Zeta performed on input *)
      ~N     (* Piped into the N function *)
        ~6   (* With 6 digits (5 decimals) *)
          &  (* Make into function *)

Mathematica result

Without builtin:

Mathematica, 23 UTF-8 bytes

Sum[1/n^#,{n,∞}]~N~6&

Thanks to Kelly Lowder


Javascript, 81 70 66 65 bytes

s=>s-1?new Int8Array(1e6).reduce((a,b,i)=>a+i**-s).toFixed(5):1/0

Runnable examples:

ζ=s=>s-1?new Int8Array(1e6).reduce((a,b,i)=>a+i**-s).toFixed(5):1/0

const values = [ 1, 2, 3, 4, 8, 19 ];
document.write('<pre>');
for(let s of values) {
  document.write('ζ(' + s + ') = ' + ζ(s) + '\n')
}


APL (Dyalog), 22 21 bytes

Look ma, no built-ins! -1 thanks to ngn.

Since Dyalog APL does not have infinities, I use Iverson's proposed notation.

{1=⍵:'¯'⋄5⍕+/÷⍵*⍨⍳!9}

Try it online!

{ anonymous function:

1=⍵: if the argument is one, then:

  '¯' return a macron

 else

  !9 factorial of nine (362880)

   first that many integers integers

  ⍵*⍨ raise them to the power of the argument

  ÷ reciprocal values

  +/ sum

  5⍕ format with five decimals

} [end of anonymous function]

Tags:

Math

Code Golf