Skip to content
DevMeme
3565 of 7435
Copilot Finds Pi's Last Digit
AI ML Post #3902, on Nov 5, 2021 in TG

Copilot Finds Pi's Last Digit

Why is this AI ML meme funny?

Level 1: Endless Number

It is like asking for the last page of a book that never ends. The computer helper grabs the last page of a tiny preview copy and says, "Here it is." That answer is funny because it solved the easy fake version, not the real question.

Level 2: Pi Is Not A String

Python is a programming language, and math.pi is its built-in approximate value for pi from the math library. Floating-point numbers are how computers store many decimal-like values, but they have limited precision. They are approximations, not infinite exact values.

The code in the image tries to turn math.pi into text with str(...), take the last character with [-1], and convert that character back into a number with int(...). That technique can work for a normal finite string like "12345", where the last digit is clearly 5. It does not work for the real pi, because pi's digits go on forever.

For newer developers, the lesson is that code can be valid Python and still be logically wrong. A generated suggestion may look smart because it uses familiar operations, but you still have to check whether the operations match the actual problem.

Level 3: Autocomplete Does Math

The screenshot shows a chat post joking that Copilot "knows how to do real math," while the embedded editor shows an AI-style completion for last_digit_of_pi. The suggestion is syntactically plausible, compact, and completely wrong for the stated concept. That is why it lands so cleanly as AI coding assistant humor.

Code-generation tools are very good at recognizing patterns: function names, nearby imports, common idioms, and snippets that often appear together. For many everyday tasks, that is useful. But math and edge cases punish pattern completion. A model sees "last digit" and reaches for "convert to string, take index -1." That is a reasonable recipe for an integer or a finite decimal string. It is nonsense for pi.

Senior developers recognize the deeper failure mode: the code satisfies the shape of the request, not the semantics. It has a function, a return statement, a standard library constant, string conversion, indexing, and integer parsing. It looks finished. But the missing step is asking whether the requested value exists. This is exactly where AI-generated content needs human review: not just "does it compile?" but "is the problem definition valid?"

The meme also pokes at a classic software habit. Developers often convert things to strings because strings are easy to slice, compare, log, and inspect. That shortcut is useful until it smuggles display formatting into program logic. Once the code depends on the last character of a formatted float, the algorithm has left mathematics and entered vibes-based serialization.

Level 4: Irrational Meets Binary64

The visible code asks for an impossible function:

def last_digit_of_pi():
    return int(str(math.pi)[-1])

Mathematically, pi has no last digit in its decimal expansion. It is irrational, so its decimal representation does not terminate or repeat. A "last digit of pi" is not merely hard to compute; it is undefined. The joke begins there: the function name describes a value that cannot exist.

The proposed implementation quietly changes the problem from "last digit of pi" to "last character of Python's printable approximation of pi." math.pi is not the infinite mathematical constant. It is a finite floating-point approximation, commonly represented as a binary64 value. That means the computer stores a nearby binary fraction using a limited number of bits. When Python turns that value into a string, it chooses a decimal representation suitable for displaying and round-tripping the finite value. The final character of that string is an artifact of formatting, precision, and rounding, not a property of pi.

So str(math.pi)[-1] is a lovely little numerical-computing trap. The [-1] indexing operation is perfectly valid Python. int(...) can parse the final character if it is a digit. The code can even return a result. That is the horrifying part: wrong programs are at their most convincing when every local operation is legal. The function does not crash; it merely answers a different question with the confidence of a calculator wearing a fake mustache.

This is why floating-point precision belongs in the punchline. The bug is not "AI bad" in a vague way. The generated code has confused a mathematical object with one machine representation of that object, then confused that representation's display string with a meaningful decimal expansion. Three layers of abstraction walked into a function name, and none of them read the requirements.

Description

A Discord-style screenshot shows user "ooliver" posting a link followed by "ah" and an embedded code editor image. The code line reads `def last_digit_of_pi():` and a gray autocomplete suggestion below it returns `int(str(math.pi)[-1])`, implying GitHub Copilot generated the implementation. The joke is that pi has no final decimal digit, while Python's `math.pi` is only a finite floating-point approximation whose string representation has an arbitrary last character. It captures both AI coding-assistant confidence and a classic numerical-computing trap.

Comments

48
Anonymous ★ Top Pick Copilot solved the last digit of pi by quietly redefining infinity as however many decimals CPython felt like printing.
  1. Anonymous ★ Top Pick

    Copilot solved the last digit of pi by quietly redefining infinity as however many decimals CPython felt like printing.

  2. @paul_thunder 4y

    Not bad. Would not do it better myself

  3. @RiedleroD 4y

    def last_digit_of_pi(): digit_i = 2 prevdigit = 3 digit = 1 while True: digit = int(math.pi*10**digit_i)%10 if digit == 0: break digit_i+=1 prevdigit=digit return prevdigit it's more complicated, so it must be better

    1. @RiedleroD 4y

      made like 5 revisions until it worked how I wanted it to lol

      1. @Dobreposhka 4y

        btw

  4. @SamsonovAnton 4y

    Wow, so Pi is a rational number at the end of all. 🤪

    1. Deleted Account 4y

      Rational numbers can have no last digit

      1. @sylfn 4y

        depends on counting system

        1. Deleted Account 4y

          Obviously...

        2. @SamsonovAnton 4y

          For example, which numeral system can express Pi as a finite set of digits, provided that the base is a natural number?

          1. @sylfn 4y

            why should I select counting system with natural number as a base?

            1. @SamsonovAnton 4y

              Because it will make little practical sense otherwise - if you start inventing individual systems for each [irrational] number.

              1. @RiedleroD 4y

                I think we were talking about theoretical technicalities

  5. @zherud 4y

    Last digit of Pi is 0 if you have Pi numeric system.

    1. @azizhakberdiev 4y

      I saw someone telling that every number ends with 000... after infinite digits after point, like 3.1415...(infinite)....00000 Then I have read one more idea: there is "999999" (six nines) part after some. Such combinations are infinite, meaning that combinations with infinite repetitive digits also exist and 0000... one of them, like 11111... 222222.... etc

      1. @sylfn 4y

        Such combinations are infinite this is proven for "finite combinations", or am I mistaken?

        1. @azizhakberdiev 4y

          Yes, sure. 10 combinations are infinite, others finite. But it is theory, our math is not ripe enough to solve these problems

      2. @RiedleroD 4y

        1/3 is 0.33333… conversely, that means 3/3=0.99999…, making the smallest possible fraction (1-0.999…) equal to zero.

        1. @RiedleroD 4y

          shit like this is why I don't like math

        2. @azizhakberdiev 4y

          Hmm. It becomes obvious that Pi in binary system ends with 0000... because of "rollover" happened with 11111... as with 99999... Zero is zero in all systems, meaning that Pi will end exactly with 0000...

          1. @sylfn 4y

            unary counting system, what is zero

          2. @RiedleroD 4y

            assuming we have a ambiguous-size floating number (aka a binary number we'd write like in our usual decimal system), we could write pi as 11.001001000011111101…

            1. @RiedleroD 4y

              so no, it's not 0 at the end, also rollover doesn't exist in floating-point mathematics

      3. @zherud 4y

        Pi in Pi numeric system is 10 so the last digit is literally 0

        1. @sylfn 4y

          last digit can be either digit with largest power of base, or least power of base, so technically, 1 can also be last digit

          1. @zherud 4y

            Yea

  6. @azizhakberdiev 4y

    0.99999.... = 1 bin 0.1111111 = 1 ?

    1. @azizhakberdiev 4y

      1 = 1 .0000000000

    2. @RiedleroD 4y

      bin 10.11101 = 2**1 2^(-1) + 2^(-2) + 2^(-3) + 2^(-5)

      1. @RiedleroD 4y

        is that understandable or too much math in one place?

        1. @azizhakberdiev 4y

          Not so bad as alien math of infinities so far

          1. @RiedleroD 4y

            …that's just how a binary counting system would work outside of computers

            1. @RiedleroD 4y

              decimal works just the same way: 3.1415 = 3*10^0 + 1*10^(-1) + 4*10^(-2) + 1*10^(-3) 5*10^(-4)

              1. @RiedleroD 4y

                maybe this extended way of writing it makes it more clear: 10.11101 = 1*2^1 + 0*2^0 + 1*2^(-1) + 1*2^(-2) + 1*2^(-3) + 0*2^(-4) + 1*2^(-5)

      2. @azizhakberdiev 4y

        So 0.11111 is 1, bc 2^(-1) + 2^(-2) + 2^(-3) + 2^(-4)... = 0.5/(1-0.5) = 1

        1. @RiedleroD 4y

          not getting your calculation, but yes, 0.1111…b would be the same as 0.99999… in decimal, therefore equal 1

          1. @azizhakberdiev 4y

            b1/(1-q)

            1. @RiedleroD 4y

              now I get it even less

              1. @azizhakberdiev 4y

                the sum of an infinitely decreasing progression

                1. @RiedleroD 4y

                  aye

        2. @RiedleroD 4y

          so this, basically

  7. @azizhakberdiev 4y

    One more proof. After infinite digits after point there will be 0 because: lim(x->infinity) 10^(-x) = 0

    1. @azizhakberdiev 4y

      But base should be greater than 1. In that case idk what the number will become

    2. @RiedleroD 4y

      error in logic: there can't come anyting after infinite digits… because it doesn't have an end. That's the point of infinity and why math breaks around it

      1. @azizhakberdiev 4y

        Ofc it has not. But what comes after infinite zeros?

        1. @RiedleroD 4y

          nothing because nothing can come after infinity anything

  8. @sylfn 4y

    Please do not violate the rules! warning 1/1 for @baophan11 for spam/ad link. Your message will be deleted

  9. @b3350541 4y

    And somebody who's class is 650 lines long knows how to do real programing

Use J and K for navigation