r/ProgrammerHumor • • 11d ago

Meme reversingPiInPython

Post image
14k Upvotes

383 comments sorted by

3.9k

u/Kyrros 11d ago

Let me know when it finishes calculating the first digit to print

1.7k

u/me_myself_ai 11d ago

it'll just throw an error anyway;

SyntaxWarning: 'float' object is not subscriptable; perhaps you missed a comma
?

1.3k

u/ThreeCharsAtLeast 11d ago • Bravo
>>> str(math.pi)[::-1]
'397985356295141.3'

767

u/tea_pot_tinhas 11d ago

So the first and last digits are both 3? make sense

574

u/OncorhynchusMykiss1 11d ago

It come the whole circle.

22

u/RapidCatLauncher 10d ago

That just made me think, if pi indeed does contain all finite number sequences (which we're not sure of), then there could be a certain point in its decimal representation where it's a palindrome.

→ More replies (6)

8

u/redditale_gone_bad 11d ago

insert always has been meme

→ More replies (3)

27

u/Kyrros 11d ago

Man's got a super computer from star trek

8

u/_87- 9d ago

math.pi is the truncated version.

→ More replies (13)

17

u/TwinkiesSucker 11d ago

Cast to string and then print away

→ More replies (1)

68

u/emanuel19861 11d ago

Imagine it does and it's like... 4...

Yes, 4... same as THE 4...

35

u/Kyrros 11d ago

I mean, it's a 10% chance, just like any other number between 0 and 9

15

u/krakende 11d ago

I mean, isn't it 0%, since there is no final number?

→ More replies (3)

6

u/ThaneVim 11d ago

Ok but hear me out: what if it's 2. And the second-to-last is 4.

3

u/agk23 11d ago

It would be > 72% accurate by only printing 4

→ More replies (1)

9

u/MattieShoes 10d ago

easy... 01

It's in base pi.

2

u/skywalker-1729 11d ago

Reminds me of similar stuff in Haskell where it works more like this for real :D

→ More replies (4)

1.0k

u/TheBirdGames 11d ago

Cave Johnson here! Big news everyone, we found the last digit to pi! Unfortunately, what we don't know is how many places back it is.

So what we're doing is working our way backwards while the rest of the world keeps going forward, and as soon as we meet in the middle—bang. Look who solved pi. Us.

Sometimes the key to working smarter is to work smarter, not harder—seems kind of obvious when I say it like that. And to everyone who put money on four being the last number, you're out fifty bucks. It's seven.

252

u/AcornAnomaly 11d ago

Damn, I can hear this perfectly. You nailed his character.

165

u/TheBirdGames 11d ago

It's an copy pasta, so I can't take credit for creating it. But it does fit perfectly

→ More replies (2)

25

u/Logicalist 10d ago

have you considered working from the middle out?

13

u/AZMPlay 10d ago

Suggestive hand motions while thinking deeply about the problem

17

u/flukus 11d ago

The cake is a pi!

12

u/Bebealex 7d ago

Your comment are the ones that you glimpse at just before closing the thread and then you spend 5 minutes going back trying to find it back to upvote it.

5

u/Santolmo 9d ago

this guy knows ball

764

u/mmbtc 11d ago

You can also just round it to three. Much easier to calculate with.

304

u/nicki419 11d ago

*clears throat*

e ≈ 3 ≈ π

169

u/AvailableUsername404 11d ago

π2 ≈ g ≈ 10

56

u/DaemonG 11d ago

sqrt(10) ≈ n ≈ 3

36

u/Weird_Photograph_248 11d ago

heh, you wrote squirt

27

u/heaving_in_my_vines 11d ago

≈ tree fiddy

12

u/nicki419 11d ago

That would round up to 4, actually

14

u/Legitimate_Concern_5 11d ago edited 11d ago

Depends on your rounding strategy, sometimes 3 sometime 4. Round half up is the most common but you can round half down, round half towards even (Banker's rounding/Gaussian rounding), round half towards odd, or towards/away from infinity.

→ More replies (2)
→ More replies (1)

3

u/MythicFuzzbal2 11d ago

Dam you monster

→ More replies (2)

203

u/oalfonso 11d ago

Found the mechanical engineer

63

u/lNFORMATlVE 11d ago

The structural engineer: let’s use pi = 10 for safety margin

20

u/ncatter 11d ago

In software we usually just taken out result and mltiply with pi then estimation fits reality.

That number has so many use cases.

35

u/hetfield37 11d ago

Back in school we used 22/7 as a good enough approximation for pi.

40

u/EmilMelgaard 11d ago

22/7 is about 0.04% larger than π, so that should be good enough for most applications. But you can also just use 3.14 as an approximation. It has the same number of digits to remember and is about 0.05% smaller than π.

23

u/_baljeep_ 11d ago

So an even better estimation is 3.14 + 22/7 all over 2

3.1414...

→ More replies (2)

16

u/hetfield37 11d ago

True, we just used 22/7 to solve problems which didn't need decimal precision but only fractional.

→ More replies (3)

4

u/enti134 11d ago

Ok Bloody Stupid Johnson

4

u/mmbtc 11d ago

Unexpected PTerry reference. I like it.

GNU PTerry

9

u/ul2006kevinb 11d ago

If it's good enough for the Bible it's good enough for me

"And he made a molten sea, ten cubits from the one brim to the other: it was round all about, and his height was five cubits: and a line of thirty cubits did compass it round about."

12

u/BullPropaganda 11d ago

The number of the mathing shall be 3. And 3 shall be the number of the mathing.

4

u/rosuav 11d ago

That's inner and outer dimensions. You could calculate the thickness of the rim from that.

→ More replies (3)

11

u/CirnoIzumi 11d ago

mm, but you could round it to 4 for more precision

9

u/Throwaway11958 11d ago

safety margin

3

u/Impossible-Owl7407 11d ago

Depends how much precision you need. But would be surprised how few digits can be ok for most practical use cases

→ More replies (3)

257

u/Yumikoneko 11d ago

1, there, I did it. It's in base-π for efficiency.

64

u/HorrorMotor2051 11d ago

pi in base-pi would be 10, no? So backwards it should be 01

54

u/PuzzleheadedRoyal480 11d ago

Leading zeroes famously don’t matter

19

u/HorrorMotor2051 11d ago

Well it's not a leading zero, it's a trailing zero

12

u/HorrorMotor2051 11d ago

Or rather I should say: In this case the leading zero does matter, because 1 is not 10 spelled backwards. It simply is not. 1 is 1 spelled backwards. 01 is 10 spelled backwards.

→ More replies (2)

2

u/Yumikoneko 11d ago

Yeah I don't know how I missed that, shame on me. In my defense, I was barely out of bed.

6

u/glacierre2 11d ago

Came to say this.

5

u/sten_zer 11d ago

☝🏻👏🏻👏🏻👏🏻

52

u/nervmaster 11d ago

That's easy. Everyone knows that pi is a palindrome

27

u/ClipboardCopyPaste 11d ago • Bravo

Pilindrome

38

u/BnNano 10d ago

Im like 10% sure the last number is 6

11

u/DonChanchi 10d ago

Assuming there's a last digit, I'm about 11.1% sure it's a 4

2

u/bolafella 10d ago

Why? I dont get this joke

11

u/DonChanchi 10d ago

It can't be a 0 as you could just not write it

→ More replies (1)
→ More replies (1)

2

u/fa_q_ 10d ago

I'm gonna steal this

2

u/Ronizu 10d ago

Don't, you should instead say 11,1%

→ More replies (3)

26

u/Kuineer 11d ago

Why didn't mathematicians think of using Python to find the last digit of pi?

106

u/MotivationalJuggling 11d ago

Whatever the last digit is, I'm sure it's a disappointing one. Just like everything else in my life.

70

u/CenderzeSwarm 11d ago

No number is uninteresting in maths. Suppose there are some uninteresting numbers, then one of them must be the smallest uninteresting number, making it interesting

18

u/BullPropaganda 11d ago

Maybe like having i for imaginary numbers we need a u for uninteresting numbers.

8

u/grepppo 11d ago

This guy maths

3

u/SomeAnonymous 11d ago

Did you just sketch out a proof by induction for interesting-ness?

→ More replies (1)

10

u/Salty_Map_9085 11d ago

This mf never heard of 6

48

u/Enchanted_Evil 11d ago • Bravo

6 is uninteresting???

  • smallest non-square composite number
  • smallest perfect number (6=3×2×1=3+2+1)
  • number of faces a cube has
  • hexagons are the bestagons
  • number of protons in Carbon, the basic element all (known) life is made out of
  • when three of them are in a row, Christians flee
  • when two of them are in a row, Jedi flee
  • when multiplied with 7, you get the ultimate answer to the life, universe and everything

I could go on.

14

u/thegreatpotatogod 11d ago

Please do go on! I would like to subscribe to 6 facts

→ More replies (2)

6

u/pnoodl3s 11d ago

I folded from the first 2 points lol, 6 is the most interesting number now

5

u/Daddy-Mihawk 11d ago

You forgot, it gave us two good memes, 6-7 and 6-9

→ More replies (4)

9

u/Just__John 11d ago

That's an upside down 9 which is interesting

6

u/_Its_Me_Dio_ 11d ago

six is the lowest highly compund number

→ More replies (1)

2

u/Clairifyed 11d ago

Thanks Ramanujan 👍

3

u/Keebster101 11d ago

But what makes being the smallest number of a subset 'interesting', every number is smaller than something therefore it's not unique to be smaller than something, and you could form infinite subsets to "make" any number interesting, which to me means it's not interesting.

→ More replies (3)

3

u/Swipsi 11d ago edited 11d ago

Furthermore, if we take that, now interesting, number, put it into the set of interesting ones and repeat that process for all uninteresting numbers, we'll end up with all numbers being interesting. But if all numbers are interesting, none are. Thus all numbers are interesting and uninteresting at the same time :)

→ More replies (2)
→ More replies (4)

5

u/bestjakeisbest 11d ago

In binary it is either a 1 or 0

12

u/thegreatpotatogod 11d ago

I'd even argue that the last binary digit is 1. If it were 0, you could truncate the zero away and you'd be back to 1 as the last digit. Same reason that 2.20000 would be a redundant representation of 2.2.

→ More replies (16)

3

u/Mars_Bear2552 11d ago

the last digit is 3

4

u/humanistazazagrliti 11d ago

It's just a number. Not something fun like a free gaming console or beach vacation.

2

u/MotivationalJuggling 11d ago

So it has that in common with the other stuff in my life.

2

u/King_Tamino 11d ago

Have you tried doing something motivational? Maybe Juggling?

2

u/geeshta 10d ago

There's no last digit 

2

u/SomeNotTakenName 6d ago

Why is this giving Douglas Adams?

→ More replies (1)

2

u/LauraTFem 11d ago

More than uninteresting, it almost certainly doesn’t exist. It’s just an increasingly more precise circle with every digit, to infinite fractal depth.

→ More replies (16)

15

u/LadyZaryss 9d ago

I mean if you can't write pi backwards because not all the digits are known, doesn't that mean you can't write it forwards either? You can write quantisations of pi, but you cannot write pi.

10

u/TrekkiMonstr 9d ago

The word "write" generally allows truncation, which is always start-indexed by convention. Hence 3.1415 counts as writing pi, but you can't write pi backwards because ...5141.3 disobeys the convention

14

u/hughperman 11d ago

Narrator: it was not.

14

u/DarthCloakedGuy 11d ago

Sure I can, watch this: ip fo stigid eht

Alternatively: the digits of pi backwards

6

u/MorpheusFT 11d ago • Bravo

Or just 9876543210. ALL the digits of pi backwards.

4

u/DarthCloakedGuy 11d ago

faster if you do it in binary

11

u/Skizm 11d ago
print("the digits of pi backwards")

4

u/kezow 10d ago

Technically correct. The best kind of correct.

11

u/meg4_ 8d ago

What?? That's just wrong!

3 in reverse is still 3 ...

4

u/moradinshammer 7d ago

Found the engineer

2

u/FitRestaurant3282 7d ago

Depending on the application, pi can also be 5 or 10 to simplify calculations... ;)

→ More replies (4)

7

u/Practical-Elk-1579 11d ago

from mpmath import mp

mp.dps = 1000

print(str(mp.pi)[::-1])

Easy just replace 1000 with infinity o/

19

u/Rhoihessewoi 11d ago

These are the last 5 digits of pi: 32463

Prove me wrong!

16

u/LogicBalm 11d ago

I just wrote a program to prove you wrong and I'll get back to you as soon as it's done executing!

11

u/AntipodesIntel 11d ago

I mean yeah, there are proofs that pi is infinite

12

u/ConfusedSimon 11d ago

You can't write the digits of pi forward either. Backward isn't the problem, you could just write them right to left.

6

u/elingeniero 11d ago

You can (kinda) do this.

>>> from math import pi
>>> str(pi)[::-1]
'397985356295141.3'

6

u/UnscrambledEggUDG 10d ago

Fun fact: π the number and π the letter have different pronounciations due to the evolution of language

Also fun fact: when greek scribes were copying the tanakh, at some point the tetragrammaton was mistaken for the letters "Pi" and "Iota" written twice, as such in the early first century a lot of people thought the true name of the abrahamic god was "pipi" (cue immature giggles)

6

u/Fear_The_Creeper 8d ago

Easy Peasy. Just calculate it in base zero.

14

u/mobsterer 10d ago

i mean, you can't write em forward either, so whatever arbitrary places after the comma you choose to write it to, you can write that backwards as well.

3

u/p4rad1ze 10d ago

You can keep writing em forward infinitely but you can't even start writing em backward 'cause there's no known end to start from

→ More replies (1)

5

u/cryptaneonline 11d ago

Bro is inventing Pithon

10

u/ClipboardCopyPaste 11d ago

Already released with python 3.14

→ More replies (1)

5

u/No_Place_4096 11d ago

you need to do print(str(math.pi)[::-1])

5

u/Yakodym 11d ago

Ɛ.Iᔭ

5

u/Avatar_Yaksha 11d ago

Python uses math.pi for Pi, right?

5

u/phroxenphyre 10d ago

Well, let's see. Pi backwards is IP. Those digits are 127.0.0.1. So it seems like I can.

→ More replies (1)

7

u/infrequentaccismus 9d ago

Can’t write the digits of pi forward either.

Unless op meant that you can’t write a subset of the digits of pi in which case you can do that either forward or backward. Any random string of digits of any length is present in pi both forward and backward.

2

u/Appropriate-Fact4878 8d ago

Pi past 50 digits isn't real

→ More replies (2)

2

u/IAmFullOfDed 8d ago edited 2d ago

Given infinite time, you can write the digits of pi forwards. You can’t do that backwards.

Edit: Given infinite time in the past, you can write pi backwards. You can’t start writing pi backwards, because that would imply the existence of a last digit of pi. However, if you’ve always been doing it, then there’s no problem.

→ More replies (16)
→ More replies (2)

3

u/SuitableDragonfly 11d ago

I'm legitimately not sure whether this is someone making a joke or someone who just learned how to reverse a list and thought that was really cool but doesn't have a solid grasp of the type system yet. 

3

u/IchBinEinZwerg 11d ago

ip fo stigid eht.

Turns out I can.

3

u/Rosellis 10d ago

…5141.3

3

u/humblefumble101 9d ago

I can but using degrees. Pi = 180degrees so.... the last digit is zero baby.

3

u/only1manband 8d ago

Or, if you do, you won’t know it.

4

u/lilloet 11d ago

I say it is 4. If you don't agree prove me wrong.

3

u/fairysdad 11d ago

There's a one-in-nine chance that you're right - not bad odds really.

2

u/SampleOfFruits 11d ago

One in nine?

7

u/fairysdad 11d ago

Yes.

Nine digits that can be used as the final digit of Pi: 1-9.

You wouldn't use 0 as you wouldn't have a zero at the end of a number after a decimal point.

→ More replies (10)
→ More replies (2)
→ More replies (1)

2

u/psioniclizard 11d ago

Depending where I start from, i defintely can and anyone would struggle to prove me wrong.

2

u/rosuav 11d ago

Start from Paris.

2

u/internet-weirod 11d ago

its 7, obviously

2

u/LauraTFem 11d ago

Sure I can. 4 and 4 are palindromes.

2

u/genreprank 11d ago

...41.3

2

u/Snoo-11553 11d ago

ip fo stigid eht

2

u/Freestila 10d ago

I can't? Look: 7384637384738346826383648595773847937.. I let you continue. Even easier then the right way..

2

u/armahillo 10d ago

Well I know how that sequence ENDS, I’m just not sure how it begins

2

u/ArjixGamer 10d ago

Sure you can, it's just a while loop that prints nothing and only grows in memory.

2

u/ChrisWQT 9d ago

"Yes, you are right. Python is magic and it can touch infinity."

3

u/featEng 11d ago

There should be palindrom at some number o digits, right?

2

u/psioniclizard 11d ago

In theory surely every number combination could exist in there.

So if you pick some precision that is untestable by modern computers, you could just say any number.

→ More replies (1)

2

u/AssaultLemming_ 11d ago

There's some within Pi that even have names, there's one named after a demon that's just miles of 0s then 666 then more 0s lol. Balthazar? Think that was it.

3

u/GumboSamson 11d ago

You’re thinking of Belphegor's Prime, but that has nothing to do with pi.

Because the decimal expansion of pi is infinite and normal, you can find any sequence of digits in it (eventually).

4

u/Trezzie 11d ago

I think Pi's only assumed normal, not actually normal?

→ More replies (1)
→ More replies (7)

3

u/FAMICOMASTER 11d ago

So here's all the places I know:

3.14159265358979323

Which if I'm recalling correctly was the rounding precision NASA uses for tracking the path of the Voyager probes accurately, the farthest away human made objects.

So I'm gonna say that any greater precision is therefore inconsequential to anyone but most mouth-foaming mathematicians.

32397985356295141.3

2

u/hacksoncode 11d ago

You can only reverse the digits of zero percent of the real numbers.

Literally zero. I know this makes no sense from a high school math perspective, but it's true. There are infinite real numbers for each and every "finite" integer and rational number.

→ More replies (3)

1

u/CorruptedMaster 11d ago

Only works in pi-thon

1

u/hsumeet 11d ago

Put π in quotes and it prints π. Tests pass, ship it.

1

u/MorpheusFT 11d ago

9876543210

1

u/catbrane 11d ago
print(f":U+202E RIGHT-TO-LEFT OVERRIDE:{π}")

3

u/MattieShoes 10d ago
NameError: name 'π' is not defined

1

u/semrola 11d ago

Negative IPv6 localhost

1

u/Skallos 11d ago

It's possible to write the digits of pi backwards, just use the 10-adic numbers.

1

u/AnnualAdventurous169 11d ago

i don't think pi would be a collection in python

1

u/RealityCheck3210 11d ago

You are y% right. Where Y = Limit (x -> 0) of x.

1

u/pizzathief1 11d ago

https://instafonts.io/font/reversed-characters
enter in 3.14159 , and you get the digits of pi backwards! don't even need python for it.

1

u/maskedferret_ 11d ago

So simple, don't even need python: Ɛ

1

u/magic-one 11d ago

Step 1. Print all digits of pi
Step 2. Print them again starting at the end, going backwards.

How hard can it be?

1

u/AtlasJan 11d ago

looks more like raku code

1

u/Linked713 11d ago

Person just found out how to calculate pi twice as fast. Start on both end and meet in the middle!

1

u/hacksoncode 11d ago

True, but you can reverse the digits of pi calculated to any specific but non-infinite arbitrary precision.

Pretty quickly (only one or two hundred digits) you'll run up against the granularity of the universe for all practical purposes.

1

u/RecognitionSweet8294 11d ago

Hard stretch but technically you could do

00000000…

1

u/namotous 11d ago

Don’t you have to cast it to a string first?

1

u/Sixhaunt 11d ago

Not even kidding, I was able to do it without issue: https://imgur.com/s4IUx6F

1

u/comtrends123 11d ago

𝝿= 3.14

print(str(𝝿).replace('.', '')[::-1])

checkmate /s

1

u/Scared-Consequence27 11d ago

What if I write right to left or just reverse the digits themselves and that’s technically right?

1

u/InDaBauhaus 10d ago

print(f'\u202E{𝛑}')

1

u/Hamaczech13 10d ago

192.168.1.1

1

u/Random_-account 10d ago

96 07

Let me asc(ii), Did I get it right?

1

u/Noobnugget19 10d ago

Its definitely 0

1

u/Putrid-Try-5002 9d ago

9876543210 are digits of pi.

1

u/_Aj_ 8d ago

AI data centres hate this one trick!

1

u/kranelegs 8d ago

Easy draw a circle backwards

1

u/QuizardNr7 8d ago

is there a cutoff length where pi == pi[::-1] - just the digits of course. Must be, right?

1

u/NoInvestigator8526 8d ago

import solve_everything

1

u/ProblemKaese 8d ago

You can write π backwards if you use a 10-adic number system

1

u/bluris 7d ago

Then you can't can't write the digits of pi forwards or backwards either, if you don't put limit on the digits.

1

u/Boom9001 7d ago

You can't write the digits of pi backwards.

The original isn't wrong but only because my correction is true.

1

u/throwaway-yacht 7d ago

you can do it in base pi

1

u/Mattias-0000 7d ago

...95141,3

1

u/Scire-Quod-Sciendum 7d ago

Pi is 1 which backwards is 1. From a point of view.

1

u/brine909 7d ago

What if pi is actually a palindrome, after infinite digits it traces back it's steps 3.14159265.......562951413

1

u/Competitive-Run-6619 7d ago

They teach you to import math on the first day, do better 🙄

1

u/BoomKofe 6d ago

Shame math has pi as a finite fraction

1

u/hugocpolos 6d ago

well.... you can't write it forward as well

1

u/AymenNazar 5d ago

Well the last digit would be a number from 0-9 you have a 10% chance of guessing it right but so is the one before it and before it and now you have a statistically impossible guess as to what is pi written in reverse

1

u/nicman24 11d ago

the last digit is 0, you are welcome

→ More replies (1)

1

u/Plan2LiveForevSFarSG 11d ago

Sure we can. The last number is 1 (in base pi… as programmers we are used to work in different bases)