-1
\$\begingroup\$

This question already has an answer here:

From Wikipedia:

The number e is an important mathematical constant that is the base of the natural logarithm. It is approximately equal to 2.71828, and is the limit of (1 + 1/n)n as n approaches infinity.

Challenge

Calculate the number e to 15 digits after the decimal point.

This means that your output must start with 2.718281828459045 or equivalent.

Your program can output digits after the required output - these may be accurate or inaccurate, inaccuracy after 15 digits does not disqualify you from the challenge. Your program may also output nothing after the required 15 digits.

This is , shortest implementation in bytes wins.

Constraints

  • You may not use built in constants or hardcode the number.
  • Standard loopholes and rules apply.

Reference Implementation (Ruby)

def e(i) 
  e = 1.0                        # make it floating point
  i.times { |n|                  # loop repeats n times
    e += 1.0/(1..n+1).reduce(:*) # factorial - no factorial function
  }                              # in the Ruby standard library
  return e
end
e(200)                           # Almost certainly will return e
\$\endgroup\$

marked as duplicate by squeamish ossifrage, LegionMammal978, TuxCrafting, Morgan Thrapp, xnor code-golf Jul 27 '16 at 18:57

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    \$\begingroup\$ Uh, the built in constant part is a bit unclear, what if I do exp(1)? What about (-1)^(1/i*pi))? \$\endgroup\$ – FryAmTheEggman Jul 27 '16 at 18:44
  • \$\begingroup\$ You mention the lim, but then your reference uses the series sum... \$\endgroup\$ – Adám Jul 27 '16 at 18:58
  • \$\begingroup\$ Sorry, a search didn't find the previous question. \$\endgroup\$ – dkudriavtsev Jul 28 '16 at 3:03
  • \$\begingroup\$ @Adám The quote is copy pasted from Wikipedia. The article also shows the series sum formula. \$\endgroup\$ – dkudriavtsev Jul 28 '16 at 3:04
  • \$\begingroup\$ @FryAmTheEggman Use your common sense. Please don't try getting around the rules. \$\endgroup\$ – dkudriavtsev Jul 28 '16 at 3:05
0
\$\begingroup\$

Haskell, 33 31 Bytes

-2 Bytes thanks to @xnor

sum[1/product[1..i]|i<-[0..99]]

Straightforward implementation of the series definition. (I have posted a version of this to Reddit before.)

\$\endgroup\$
  • \$\begingroup\$ You don't need parens around the product. \$\endgroup\$ – xnor Jul 27 '16 at 18:50
0
\$\begingroup\$

Haskell, 25 bytes

f 99=0;f n=1+f(n+1)/n;f 0

26 bytes:

foldr(\x y->1+y/x)0[1..99]
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.