# Golf a transcendental number

## 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.

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.

• 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
– WNG
May 16 '17 at 18:45
• @WNG Languages have arbitrary precision. There is no maxinteger. May 16 '17 at 18:45
• @WNG You can think of the input index as a string, not an integer, in languages that don't have arbitrarily large number types. May 18 '17 at 0:25

# 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.

• I would be quite excited to see the proof. May 15 '17 at 3:01
• 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'.
– Mast
May 16 '17 at 8:02
• @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.
– xnor
May 16 '17 at 9:00
• delightful :))) May 17 '17 at 4:49
• Holy sh1t, this is clever!
– RGS
Feb 10 '20 at 18:21

# 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.

• 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. May 16 '17 at 15:46

# 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!

• 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.
– orlp
May 15 '17 at 2:54
• – xnor
May 15 '17 at 2:56
• @orlp Fredholm's number May 15 '17 at 2:57
• @orlp I'd have to ask the OP if Booleans are fine. May 15 '17 at 2:57
• @Scrooble These Booleans. Apr 23 '18 at 1:41

# brainfuck, 2 bytes

,.


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

# Jelly, 3 bytes

e!€


Uses Liouville's constant.

Try it online!

## 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.

# 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.

• Why do you need ⟦₁? May 15 '17 at 2:39
• @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).
– user62131
May 15 '17 at 2:41

# 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.

• You should include why this number is transcendental.
– orlp
May 15 '17 at 2:57
• @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). May 15 '17 at 3:46

# 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)


# 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>

# Python 2, 43 bytes

Champernowne's constant.

lambda n:"".join(ifor i in range(n+1))[n]

• Why do you need n+1? May 15 '17 at 2:39
• @LeakyNun Because else I get indexing errors for n <= 1.
– orlp
May 15 '17 at 2:40
• You can use 1-indexing. May 15 '17 at 2:40
• @LeakyNun n <= 1.
– orlp
May 15 '17 at 2:40
• I think you need to specify Python 2 for this one. May 15 '17 at 7:18

# 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.

• 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. May 15 '17 at 18:30
• @ØrjanJohansen You can express it as 1 - 10^-9 + 10^-99 - 10^-999 + 10^-9999 - 10^-99999 + ..., so it is a Liouville number. May 16 '17 at 8:21
• @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. May 16 '17 at 16:05

# 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..]  • =<< from the list monad is concat.map: (!!)$show=<<[1..].
– nimi
Sep 16 '18 at 15:01

# 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!

# Pyth, 75 4 bytes

@jkS


Try it online!

Uses Champernowne's constant.

Saved 2 3 bytes thanks to Leaky Nun.

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

# Java 8, 18 bytes

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

n->(n&(n-1))>0?0:1

• (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). Apr 23 '18 at 7:59

# Jelly, 1 byte

Ḣ


Try it online!

1st digit of quoted 0-indexed input.1

1See isaacg's answer for proof of validity.

# Charcoal, 24 bytes (noncompeting)

ＮαＡＩＵＶN⟦ＵＧPi⁺α¹⟧β§β⁺α›α⁰


Try it online!

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

# Explanation

Ｎα                             Input number to a
Ａ                  β        Assign to b
Ｉ                         Cast
ＵＶN                    Evaluate variable N
⟦ＵＧPi⁺α¹⟧         With arguments GetVariable(Pi) and a+1
§β⁺α›α⁰ Print b[a+(a>0)]

• GetVariable(Pi)? So, there's no π predefined variable?
– Neil
May 15 '17 at 18:30
• @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 May 15 '17 at 22:50

# Japt, 31+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

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

# 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


# 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)


# 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)


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

({}<>)


Try it online!

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

# C#, 13 bytes

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


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

Try it online

# 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!

# 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.

# Jelly, 2 bytes

LḂ


Try it online!

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

7 3 6


Try it online!

Returns the first digit of the input.

# Momema, 5 bytes

-9*-9


Try it online!

Returns the first digit of the input.

# Shakespeare Programming Language, 76 bytes

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


Try it online!

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