Beta

Digits of e

5 of 7Dr Gabo

Description:

About Euler's Number

Euler's Number (commonly called e), is a famous irrational constant that arises in lots of different contexts related to mathematics and engineering. It can be expressed as:

Source: Wikipedia

But there are multiple ways of approximating e, being ones more efficient than others. Some methods might become unfeasible over a certain precision level.

Your task

Write a function int calc_e(unsigned int n) that takes a number n and returns the n-th digit of e.

Technical notes:

  • There is a limit of 700 bytes (not characters) to prevent hardcoding.
  • Only values of n in the range [0, 10000] (both included) will be tested.
    • 50 first digits.
    • 200 random tests in the range [0, 1000].
    • 200 random tests in the range [1000, 5000].
    • 200 random tests in the range [5000, 10000].
  • Mind the performance!
  • This kata performs an anti-cheat analysis, so your code might be flagged as wrong if you use suspicious snippets (such as preprocessor or other programming languages). You should avoid interacting with the system (opening files, executing commands, etc).

Examples

// e ≈ 2.718281828459045...

e_digit(0) == 2
e_digit(1) == 7
e_digit(2) == 1
e_digit(3) == 8
e_digit(4) == 2
Mathematics
Performance
Algorithms

Stats:

CreatedApr 17, 2020
PublishedApr 17, 2020
Warriors Trained132
Total Skips31
Total Code Submissions93
Total Times Completed7
C++ Completions5
Total Stars2
% of votes with a positive feedback rating100% of 2
Total "Very Satisfied" Votes2
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • Dr Gabo Avatar
Ad