46
\$\begingroup\$

Definitions

  • An algebraic number is a number that is a zero of a non-zero polynomial with integer coefficients. For example, the square root of 2 is algebraic, because it is a zero of x^2 - 2.
  • A transcendental number is a real number which is not algebraic.

Task

You are to choose a transcendental number.

Then, write a program/function that takes a positive integer n and output the n-th decimal digit after the decimal point of your chosen transcendental number. You must state clearly in your submission, which transcendental number is used.

You can use 0-indexing or 1-indexing.

Example

e^2=7.389056098... is a transcendental number. For this number:

n output
1 3
2 8
3 9
4 0
5 5
6 6
7 0
8 9
9 8
...

Note that the initial 7 is ignored.

As I mentioned above, you can choose other transcendental numbers.

Scoring

This is . Lowest score in bytes wins.

\$\endgroup\$
  • \$\begingroup\$ How do the different answers handle the fact that there is a finite number of integers that can be used as an argument? 0 would be an acceptable answer since a transcendental number exists whose first maxInteger digits are 0 \$\endgroup\$ – WNG May 16 '17 at 18:45
  • 1
    \$\begingroup\$ @WNG Languages have arbitrary precision. There is no maxinteger. \$\endgroup\$ – Leaky Nun May 16 '17 at 18:45
  • 1
    \$\begingroup\$ @WNG You can think of the input index as a string, not an integer, in languages that don't have arbitrarily large number types. \$\endgroup\$ – isaacg May 18 '17 at 0:25

30 Answers 30

112
+500
\$\begingroup\$

Python, 3 bytes

min

Try it online!

Takes a number string, outputs its smallest digit as a smallest character. For example, 254 gives 2. The decimal with these digits starts

0.0123456789011111111101222222220123333333012344444401234555550123456666012345678801234567

This is OEIS A054054.

Claim: This number c is transcendental

Proof: Note that c is very sparse: almost all of its digits are zero. That's because large n, there's high probability n has a zero digit, giving a digit min of zero. Moreover, c has long runs of consecutive zeroes. We use an existing result that states this means c is transcendental.

Following this math.SE question, let Z(k) represent the position of the k'th nonzero digit of c, and let c_k be that nonzero digit, a whole number between 1 and 9. Then, we express the decimal expansion of c, but only taking the nonzero digits, as as the sum over k=1,2,3,... of c_k/10^Z(k).

We use the result of point 4 of this answer by George Lowther: that c is transcendental if there are infinitely many runs of zeroes that are at least a constant fraction of the number of digits so far. Formally, there must be an ε>0 so that Z(k+1)/Z(k) > 1+ε for infinitely many k. We'll use ε=1/9

For any number of digits d, take k with Z(k) = 99...99 with d nines. Such a k exists because this digit in c is a 9, and so nonzero. Counting up from 99...99, these numbers all contain a zero digit, so it marks the start of a long run of zeroes in c. The next nonzero digit isn't until Z(k+1) = 1111...11 with d+1 ones. The ratio Z(k+1)/Z(k) slightly exceeds 1+1/9.

This satisfies the condition for every d, implying the result.

\$\endgroup\$
  • \$\begingroup\$ I would be quite excited to see the proof. \$\endgroup\$ – Leaky Nun May 15 '17 at 3:01
  • 1
    \$\begingroup\$ Is this allowed? min itself doesn't take any input and doesn't provide any output, something that seems to be a requirement by the question. Sure, it's the key function in the whole, but it doesn't do anything without the generator and print statement apparent in the 'Try it online'. \$\endgroup\$ – Mast May 16 '17 at 8:02
  • 6
    \$\begingroup\$ @Mast Yes, the problem is to output the n'th digit given n, not to generate the decimal. The test code is to show the sequence of digits. And an expression that evaluates to a function, including a function literal, is a valid function submission. \$\endgroup\$ – xnor May 16 '17 at 9:00
  • 1
    \$\begingroup\$ delightful :))) \$\endgroup\$ – Noodle9 May 17 '17 at 4:49
38
\$\begingroup\$

Pyth, 1 byte

h

Input and output are strings. The function takes the first digit of the index. The resulting transcendental number looks like:

0.0123456789111111111122222222223 ...

This is transcendental because it is 1/9 plus a number which has stretches of zeroes of length at least a constant fraction of the number. Based on this math.stackexchange answer, that means that the number is transcendental.

There are stretches of zeroes are from digit 100 ... 000 to 199 ... 999, so ratio of Z(k+1) to Z(k) is 2 infinitely often.

Thus, the above number minus 1/9 is transcendental, and so the above number is transcendental.

\$\endgroup\$
  • 1
    \$\begingroup\$ Note that the question asked in the linked M.SE post does not apply to this number, but point 4 of the answer by George Lowther does. \$\endgroup\$ – Henning Makholm May 16 '17 at 15:46
16
\$\begingroup\$

Python 2, 19 bytes

lambda n:1>>(n&~-n)

The nth digit is 1 if n is a power of 2 and 0 otherwise.

Try it online!

\$\endgroup\$
  • 3
    \$\begingroup\$ I was going to answer this, but I found no proof of its transcendence. What makes you believe this number is transcendent? n&~-n>0 is shorter by the way. \$\endgroup\$ – orlp May 15 '17 at 2:54
  • 3
    \$\begingroup\$ @orlp All sufficiently sparse numbers are transcendental. \$\endgroup\$ – xnor May 15 '17 at 2:56
  • 1
    \$\begingroup\$ @orlp Fredholm's number \$\endgroup\$ – Leaky Nun May 15 '17 at 2:57
  • \$\begingroup\$ @orlp I'd have to ask the OP if Booleans are fine. \$\endgroup\$ – Dennis May 15 '17 at 2:57
  • 1
    \$\begingroup\$ @Scrooble These Booleans. \$\endgroup\$ – Dennis Apr 23 '18 at 1:41
11
\$\begingroup\$

brainfuck, 2 bytes

,.

Similarly to some other answers, returns the first decimal digit and ignores the rest.

\$\endgroup\$
6
\$\begingroup\$

Jelly, 3 bytes

e!€

Uses Liouville's constant.

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Retina, 4 bytes

1!`.

Returns the first digit of the input number. Because that port was so boring, here are some more ports:

O`.
1!`.

(8 bytes) Returns the minimum digit of the input number.

.+
$*
+`^(11)+$
$#1$*
^1$

(25 bytes) Returns 1 if the input number is a power of 2.

.+
$*_

$.`
+1`.(\d*)_
$1
1!`.

(30 bytes) Champernowne's constant.

\$\endgroup\$
4
\$\begingroup\$

Brachylog 2, 7 bytes

⟦₁c;?∋₎

Try it online!

Calculates digits of the Champernowne constant (possibly times a power of ten due to indexing issues, which clearly don't matter here). Basically, this just concatenates together integers, and then takes the nth digit.

\$\endgroup\$
  • \$\begingroup\$ Why do you need ⟦₁? \$\endgroup\$ – Leaky Nun May 15 '17 at 2:39
  • \$\begingroup\$ @LeakyNun: Because otherwise we'd start concatenating numbers with 0, and you can't do that because 0123 is not a number (it has a leading zero, which doesn't fit within Brachylog's concept of what a number is). \$\endgroup\$ – user62131 May 15 '17 at 2:41
4
\$\begingroup\$

Python 2, 13 bytes

Input and output are strings.

lambda n:n[0]

The number's nth digit is the most significant digit of n when it is written in decimal.

\$\endgroup\$
  • 4
    \$\begingroup\$ You should include why this number is transcendental. \$\endgroup\$ – orlp May 15 '17 at 2:57
  • 2
    \$\begingroup\$ @orlp Looks like xnor's reference can easily be applied here too -- subtract 1/9 from the number and then Z(n+1) / Z(n) ~= 2 infinitely often (between 10^x and 2 * 10^x). \$\endgroup\$ – feersum May 15 '17 at 3:46
4
\$\begingroup\$

MATL, 7 bytes

4YA50<A

This uses the first of the two numbers given here divided by 3 (which maintains transcendence):

1.100110000000000110011...

Input is 1-based. Try it online! Or see the first 20 decimals.

Explanation

4YA     % Convert to base 4 using chars '0', '1', '2', '3' as digits
50<A    % Are all digits less than '2'? Gives 0 (false) or 1 (true) 
\$\endgroup\$
3
\$\begingroup\$

JavaScript, 51 bytes

This function computes nth digit of Champernowne's Constant. Add f= at the beginning and invoke like f(arg). Note that n is 1-indexed.

n=>[..."1".repeat(n)].map((c,i)=>c*++i).join``[n-1]

Explanation

This function takes in a single argument n. It, then, creates an n-characters long String of repetitive 1s. Then, it splits that String into an Array of 1s . After that, it iterates over every element of the Array and multiplies them with their index in the Array incremented by 1. Then, it joins the Array together over "" (empty String) to form a String. At last, it returns the nth element of the obtained String.

Note: The type of the returned value is always String.

Test Snippet

let f =

n=>[..."1".repeat(n)].map((c,i)=>c*++i).join``[n-1]

i.oninput = e => o.innerHTML = f(parseInt(e.target.value,10));
<input id=i><pre id=o></pre>

\$\endgroup\$
3
\$\begingroup\$

Python 2, 43 bytes

Champernowne's constant.

lambda n:"".join(`i`for i in range(n+1))[n]
\$\endgroup\$
  • \$\begingroup\$ Why do you need n+1? \$\endgroup\$ – Leaky Nun May 15 '17 at 2:39
  • \$\begingroup\$ @LeakyNun Because else I get indexing errors for n <= 1. \$\endgroup\$ – orlp May 15 '17 at 2:40
  • \$\begingroup\$ You can use 1-indexing. \$\endgroup\$ – Leaky Nun May 15 '17 at 2:40
  • \$\begingroup\$ @LeakyNun n <= 1. \$\endgroup\$ – orlp May 15 '17 at 2:40
  • \$\begingroup\$ I think you need to specify Python 2 for this one. \$\endgroup\$ – numbermaniac May 15 '17 at 7:18
3
\$\begingroup\$

APL (Dyalog), 3 bytes

2|⍴

Try it online! (the test suite generates a range of numbers from 1 to 10000, converts them to a string, and then applies the train 2|⍴ on them).

Takes the input number as a string and returns its length mod 2. So 123 => 3 mod 2 => 1.

The sequence starts off like so:

1  1  1  1  1  1  1  1  1  0  0  0  0  0  0  ...

so this can be generalised like so: 9 1s 90 0s 900 1s ...

Multiplying this number by 9 gives us a Liouville number, which is proven to be transcendental.

\$\endgroup\$
  • \$\begingroup\$ I don't think this is necessarily a Liouville number - it's not obvious to me that you can get n>10. It does fit the stronger theorem other people here have been using, though. \$\endgroup\$ – Ørjan Johansen May 15 '17 at 18:30
  • \$\begingroup\$ @ØrjanJohansen You can express it as 1 - 10^-9 + 10^-99 - 10^-999 + 10^-9999 - 10^-99999 + ..., so it is a Liouville number. \$\endgroup\$ – Leaky Nun May 16 '17 at 8:21
  • \$\begingroup\$ @LeakyNun The fraction of consecutive exponents is approximately 10, but to fit the definition on Wikipedia it needs to be unbounded - that's why the original Liouville's constant's 1-indices use a factorial, and not an exponential. \$\endgroup\$ – Ørjan Johansen May 16 '17 at 16:05
3
\$\begingroup\$

Haskell, 25 bytes 17 bytes

(!!)$concat$map show[1..]

Champernowne's Constant can be 0 or 1 indexed as C10*.01 is still transcendental.

Edit: as per nimis comment you can use the list monad to reduce this to

(!!)$show=<<[1..]
\$\endgroup\$
  • 2
    \$\begingroup\$ =<< from the list monad is concat.map: (!!)$show=<<[1..]. \$\endgroup\$ – nimi Sep 16 '18 at 15:01
2
\$\begingroup\$

JavaScript, 73 bytes

This is a program which computes the nth digit of the Liouville Constant, where n is the input number given by invoking the function g as g(arg) (and n is 1-indexed). Note that the newline in the code is necessary.

f=n=>n<1?1:n*f(n-1);g=(n,r=0)=>{for(i=0;i<=n;i++)if(f(i)==n)r=1
return r}

Explanation

The program consists of two functions, f and g. f is a recursive factorial-computing function, and g is the main function of the program. g assumes to have a single argument n. It defines a default argument r with a value of 0. It, then, iterates over all the Integers from 0 to n, and, in each iteration, checks whether the function f applied over i (the current index) equals n, i.e. whether n is a factorial of i. If that happens to be the case, r's value is set to 1. At the end of the function, r is returned.

Snippet for Testing

f=n=>n<1?1:n*f(n-1);g=(n,r=0)=>{for(i=0;i<=n;i++)if(f(i)==n)r=1
return r}

i.oninput = e => o.innerHTML = g(parseInt(e.target.value,10))
<input id=i><pre id=o></pre>

Warning: Don't put a very large value in the Snippet's input box! Otherwise, your device may freeze!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 7 5 4 bytes

@jkS

Try it online!

Uses Champernowne's constant.

Saved 2 3 bytes thanks to Leaky Nun.

\$\endgroup\$
  • 1
    \$\begingroup\$ you can use jk to replace sm`d, I believe. \$\endgroup\$ – Leaky Nun May 15 '17 at 2:42
  • 1
    \$\begingroup\$ Can you use S instead of Uh? \$\endgroup\$ – Leaky Nun May 15 '17 at 2:49
  • \$\begingroup\$ I think they are functionally identical, so yes. I totally read through the docs >.> \$\endgroup\$ – clap May 15 '17 at 2:54
  • \$\begingroup\$ They aren't functional identical. S starts with 1 and U starts with 0. \$\endgroup\$ – Leaky Nun May 15 '17 at 2:55
  • \$\begingroup\$ Why did you revert your edit? The resulting number is still transcendental. \$\endgroup\$ – Leaky Nun May 15 '17 at 2:56
1
\$\begingroup\$

Java 8, 18 bytes

Same as Dennis' answer for Python 2, the Fredholm number

n->(n&(n-1))>0?0:1
\$\endgroup\$
  • \$\begingroup\$ (n-1) can be ~-n or --n to save 2 bytes. Or you can have the exact same as Dennis' answer: n->1>>(n&~-n) or 1>>(n&--n). \$\endgroup\$ – Kevin Cruijssen Apr 23 '18 at 7:59
1
\$\begingroup\$

Jelly, 1 byte

Try it online!

1st digit of quoted 0-indexed input.1

1See isaacg's answer for proof of validity.

\$\endgroup\$
1
\$\begingroup\$

Charcoal, 24 bytes (noncompeting)

NαAIUVN⟦UGPi⁺α¹⟧β§β⁺α›α⁰

Try it online!

Note: As of post time, does not work for n where n is a positive multiple of 14.

Explanation

Nα                             Input number to a
   A                  β        Assign to b
     I                         Cast
       UVN                    Evaluate variable N
            ⟦UGPi⁺α¹⟧         With arguments GetVariable(Pi) and a+1
                        §β⁺α›α⁰ Print b[a+(a>0)]
\$\endgroup\$
  • \$\begingroup\$ GetVariable(Pi)? So, there's no π predefined variable? \$\endgroup\$ – Neil May 15 '17 at 18:30
  • \$\begingroup\$ @Neil Not yet, and I'm not intending to make π equal to pi because this is an ASCII-art oriented language, not a math-oriented one \$\endgroup\$ – ASCII-only May 15 '17 at 22:50
1
\$\begingroup\$

Japt, 3 1+1= 2 1 byte

Another port of feersum's solution.

Takes input as a string.

g

Try it online


Explanation

   :Implicit input of string U
g  :The first character of the string
\$\endgroup\$
  • \$\begingroup\$ The input can be a string, so you can do g for 1 byte :) \$\endgroup\$ – Oliver May 18 '17 at 21:00
  • \$\begingroup\$ The challenge doesn't make mention of string input, @obarakon, so I used integers in my JS ports and then, in turn, here. \$\endgroup\$ – Shaggy May 18 '17 at 21:27
  • \$\begingroup\$ Ah, gotcha. A lot of the other answers used string inputs. But you're right, the OP didn't mention it in the challenge. \$\endgroup\$ – Oliver May 19 '17 at 13:59
1
\$\begingroup\$

TI-BASIC, 16 bytes

Basically tests if the input N (1-indexed) is a triangular number. This is the same as returning the Nth digit of 0.1010010001…, which is proven to be transcendental. The sequence of digits is OEIS A010054.

Input N
int(√(2N
2N=Ans(Ans+1
\$\endgroup\$
0
\$\begingroup\$

Fourier, 16 bytes

I~NL~S10PS~XN/Xo

Try it online!

As other answers have done, outputs the first digit of the input.

An explanation of the code:

N = User Input
S = log(N)
X = 10 ^ S
Print (N/X)
\$\endgroup\$
0
\$\begingroup\$

JavaScript (ES6)

Just a few ports of some other solutions


feersum's Python solution, 12 bytes

n=>(""+n)[0]

f=
n=>(""+n)[0]
o.innerText=f(i.value=1)
i.oninput=_=>o.innerText=f(+i.value)
<input id=i type=number><pre id=o>


Dennis' Python solution, 13 bytes

n=>1>>(n&--n)

f=
n=>1>>(n&--n)
o.innerText=f(i.value=1)
i.oninput=_=>o.innerText=f(+i.value)
<input id=i type=number><pre id=o>


xnor's Python solution, 20 bytes

n=>Math.min(...""+n)
\$\endgroup\$
0
\$\begingroup\$

Brain-Flak, 6 + 3 ( -c) = 9 bytes

({}<>)

Try it online!

1st digit of 0-index string input (hence the -c flag).

\$\endgroup\$
0
\$\begingroup\$

C#, 13 bytes

n=>(n+"")[0];

From feersum's solution. Almost same solution than the js port.

Try it online

\$\endgroup\$
0
\$\begingroup\$

05AB1E, 3 1 byte

EDIT: Using the proof from the other answers, returns the first digit of input

¬

1-indexed for π (only up to 100000 digits)

žs¤

How it works

žs  # Implicit input. Gets n digits of pi (including 3 before decimal)
  ¤ # Get last digit

Or, if you prefer e (still 1-indexed) (only up to 10000 digits)

žt¤

Try it online!

\$\endgroup\$
0
\$\begingroup\$

J, 2 Bytes

The same solution everyone else is using:

{.

Returns the first digit of n. IO is on strings

Liouville's Constant, 9 Bytes

(=<.)!inv

Returns 1 if input is the factorial of an integer.

Pi, 13 Bytes

{:":<.@o.10x^

The last non-decimal digit of pi times 10^n.

\$\endgroup\$
0
\$\begingroup\$

Jelly, 2 bytes

LḂ

Try it online!

Take the length of the input number modulo 2. Equivalent to this APL answer.

\$\endgroup\$
0
\$\begingroup\$

Dreaderef, 5 bytes

7 3 6

Try it online!

Returns the first digit of the input.

\$\endgroup\$
0
\$\begingroup\$

Momema, 5 bytes

-9*-9

Try it online!

Returns the first digit of the input.

\$\endgroup\$
0
\$\begingroup\$

Shakespeare Programming Language, 76 bytes

,.Ajax,.Ford,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Open mind.Speak thy.

Try it online!

\$\endgroup\$
  • \$\begingroup\$ You've got an extra character there \$\endgroup\$ – Jo King Sep 11 '18 at 12:07
  • \$\begingroup\$ Whoops, that must have been a leftover from something else. Thanks for spotting it. \$\endgroup\$ – JosiahRyanW Sep 11 '18 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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