Given an input n, output the value of the Fransén-Robinson constant with n digits after the decimal place, with rounding.

Rules

  • You may assume that all inputs are integers between 1 and 60.
  • You may not store any related values - the constant must be calculated, not recalled.
  • Rounding must be done with the following criteria:
    • If the digit following the final digit is less than five, the final digit must remain the same.
    • If the digit following the final digit is greater than or equal to five, the final digit must be incremented by one.
  • You must only output the first n+1 digits.
  • Standard loopholes apply.

Test Cases

>>> f(0)
3

>>> f(1)
2.8

>>> f(11)
2.80777024203

>>> f(50)
2.80777024202851936522150118655777293230808592093020

>>> f(59)
2.80777024202851936522150118655777293230808592093019829122005

>>> f(60)
2.807770242028519365221501186557772932308085920930198291220055
  • What if you do not have support for arbitrary precision floats? – flawr May 27 '16 at 22:10
  • 1
    @flawr I suppose that the language would have to use some form of string concatenation or similar. Otherwise, it may not be the language for this challenge. – Addison Crump May 27 '16 at 22:11
  • Too bad, that basically only leaves us with hardcoding the numbers. PS: Why don't you add f(60) to the test cases? That way participants wouldn't have to fetch it externally=) – flawr May 27 '16 at 22:14
  • @flawr Hardcoding is disallowed by rule 2. – Addison Crump May 27 '16 at 22:15
  • Are trailing zeroes ok? – Mego May 27 '16 at 23:41
up vote 7 down vote accepted

Mathematica, 44 39 36 25 UTF-8 bytes

  • -5 bytes thanks to Sp3000
  • -3 bytes thanks to kennytm
  • -11 bytes thanks to senegrom

Crossed out 44 is still regular 44!!

N[∫1/x!{x,-1,∞},#+1]&

Example:

f=N[∫1/x!{x,-1,∞},#+1]&
f[2]

Outputs 2.81.

Explanation

N[               , # + 1] 
  ∫1/x!{x,-1,∞}

First step takes Numeric of the rest, with # (first parameter) + 1 precision. ! (factorial) does what you'd expect. {x, -1, Infinity} sets the bounds for the (strangely formatted) Integral.

  • I can't test this, so I assume this rounds correctly? – Addison Crump May 27 '16 at 23:03
  • 1
    @VTCAKAVSMoACE I checked for n = 60, it rounds correctly. (The 61st digit is an 8). You can look at Wolfram's docs for N. – NoOneIsHere May 27 '16 at 23:04
  • Coolio. Just checking. – Addison Crump May 27 '16 at 23:04
  • You can probably use a literal in place of Infinity. I'd suggest dividing by 0, if that didn't produce ComplexInfinity instead... – Sp3000 May 28 '16 at 4:44
  • 1
    try N[∫1/x!{x,-1,∞},#+1]& where is Unicode-F74C; displays as 𝕕 in Mathematica. (note that the space before & is also not necessary...) – senegrom Jun 2 '16 at 11:19

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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