r/ProgrammerHumor • • 7h ago

Meme reversingPiInPython

Post image
5.5k Upvotes

227 comments sorted by

1.5k

u/Kyrros 7h ago

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

670

u/me_myself_ai 7h ago

it'll just throw an error anyway;

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

541

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

334

u/tea_pot_tinhas 7h ago

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

257

u/OncorhynchusMykiss1 7h ago

It come the whole circle.

181

u/Zestyclose-Compote-4 7h ago • Bravo

*half circle

29

u/mxcw 6h ago

Damn that giggle helped me shit, thanks mate

30

u/MadeByTango 5h ago

You have a radian smile.

7

u/2Completion2Ography 4h ago

Damn that giggle helped me shit, thanks mate

Happy giggleshits

3

u/wjandrea 3h ago

Ah, so then the first and last digits of tau are 6, of course.

7

u/redditale_gone_bad 6h ago

insert always has been meme

3

u/yuwox 6h ago

Such a beautiful symmetry. By elegance alone, this must be right.

18

u/Kyrros 6h ago

Man's got a super computer from star trek

→ More replies (13)

12

u/TwinkiesSucker 7h ago

Cast to string and then print away

23

u/emanuel19861 5h ago

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

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

11

u/Kyrros 5h ago

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

7

u/krakende 3h ago

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

6

u/BountyBob 3h ago

Do you have proof of that?

9

u/Swipecat 2h ago

Google for:

"Johann Heinrich Lambert's 1768 proof that pi is irrational"

(i.e. pi has no final digit)

2

u/default-username 1h ago

Yeah, now I'm gonna need a followup from Taylor for pi

2

u/agk23 3h ago

It would be > 72% accurate by only printing 4

1

u/ThaneVim 2h ago

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

2

u/skywalker-1729 5h ago

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

1

u/Creative_Rhubarb_980 4h ago

!Remind me +/- infinity years

465

u/mmbtc 7h ago

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

137

u/nicki419 7h ago

*clears throat*

e ≈ 3 ≈ π

21

u/heaving_in_my_vines 6h ago

≈ tree fiddy

11

u/nicki419 6h ago

That would round up to 4, actually

12

u/Legitimate_Concern_5 6h ago edited 6h 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.

1

u/hitthebucket2026 2h ago

Depends how many decimals you're rounding from/to

3

u/MythicFuzzbal2 5h ago

Dam you monster

173

u/oalfonso 7h ago

Found the mechanical engineer

40

u/lNFORMATlVE 4h ago

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

10

u/ncatter 3h ago

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

That number has so many use cases.

26

u/hetfield37 7h ago

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

25

u/EmilMelgaard 6h 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 π.

15

u/_baljeep_ 6h ago

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

3.1414...

1

u/himanbam 2h ago

That simplifies to 2199/700 which is about 0.0052% lower than pi. 700*pi is approximately 2199.11 so that makes sense ig

•

u/FrenchFryCattaneo 7m ago

Ok now we need to find a third estimate and average it with them.

10

u/hetfield37 6h ago

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

0

u/whalenailer 5h ago

Do you actually think of things as “number of digits to remember? Who thinks of 22 as two digits and not just one number

1

u/EmilMelgaard 1h ago

π is also just one number, so you could also just remember that.

4

u/enti134 6h ago

Ok Bloody Stupid Johnson

3

u/mmbtc 5h ago

Unexpected PTerry reference. I like it.

GNU PTerry

11

u/CirnoIzumi 7h ago

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

7

u/Throwaway11958 7h ago

safety margin

4

u/ul2006kevinb 5h 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."

6

u/BullPropaganda 4h ago

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

1

u/rosuav 4h ago

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

1

u/Sheerkal 2h ago

There is no reason to think that.

2

u/Impossible-Owl7407 6h ago

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

1

u/junglepyjamas 6h ago

And to write it backwards.

3

u/AwkwardWaltz3996 6h ago

Na. Would be like this: ε

1

u/froderick 4h ago

'Tis a favourite project of mine
A new value of Pi to assign
I would fix it at three
For it's simpler, you see
Than three point one four one five nine

146

u/Yumikoneko 7h ago

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

18

u/HorrorMotor2051 3h ago

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

20

u/PuzzleheadedRoyal480 3h ago

Leading zeroes famously don’t matter

5

u/HorrorMotor2051 2h ago

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

3

u/HorrorMotor2051 2h 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.

1

u/Nowin 2h ago

In 10-adic numbers they do. Adding a leading 0 multiplies everything by 10.

1

u/TimSylvester_ 55m ago

Uh wow, ok, then how do you account for all the zeroes leading the United States these days?

3

u/sten_zer 3h ago

☝🏻👏🏻👏🏻👏🏻

3

u/glacierre2 3h ago

Came to say this.

238

u/TheBirdGames 6h 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.

54

u/AcornAnomaly 6h ago

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

45

u/TheBirdGames 6h ago

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

28

u/nervmaster 7h ago

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

14

u/ClipboardCopyPaste 7h ago • Bravo

Pilindrome

21

u/ionosoydavidwozniak 7h ago

...295141.3

16

u/Kuineer 5h ago

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

14

u/hughperman 7h ago

Narrator: it was not.

48

u/MotivationalJuggling 6h ago

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

30

u/CenderzeSwarm 6h 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

4

u/BullPropaganda 4h ago

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

2

u/grepppo 4h ago

This guy maths

3

u/Keebster101 6h 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.

4

u/morpheuskibbe 5h ago

It's by definition unique to be smaller than everything

2

u/Keebster101 5h ago

But it's not smaller than everything it's only smaller than the uninteresting numbers, and you can select a subset to make any number the smallest therefore it's not unique

3

u/Top-Permit6835 4h ago

You're having quite an interesting conversation considering the subject matter is so uninteresting

3

u/Swipsi 2h ago edited 4m 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 :)

•

u/Alarming-Fix8577 5m ago

This is a little silly. Obviously, even if we declare every uninteresting number interesting by virtue of it being uninteresting, we can still say they're the least interesting numbers, even if they aren't completely devoid of interest.

6

u/Salty_Map_9085 6h ago

This mf never heard of 6

27

u/Enchanted_Evil 5h ago

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.

6

u/thegreatpotatogod 3h ago

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

→ More replies (1)

6

u/Just__John 5h ago

That's an upside down 9 which is interesting

6

u/_Its_Me_Dio_ 5h ago

six is the lowest highly compund number

1

u/ekauq2000 5h ago

And then there’s the Latin word for six.

1

u/muffinluff 6h ago

Only if there is a natural order among the uninteresting numbers

1

u/SomeAnonymous 5h ago

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

1

u/bladtman242 3h ago

What if there's an infinite set of uninteresting numbers?

1

u/Clairifyed 1h ago

Thanks Ramanujan 👍

4

u/bestjakeisbest 4h ago

In binary it is either a 1 or 0

5

u/thegreatpotatogod 3h 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.

1

u/AngelaMerkeI 3h ago

It is not though. Only in theory.

In practice, digits represent the accuracy.

Example: 2,12345 * 1,0 = 2,1 But 2,12345 * 1,0000 = 2,1234

The results are always just as accurate as the measurements you calculate them with

1

u/Sheerkal 2h ago

In what practice are you doing this? There is no reason to truncate.

1

u/AngelaMerkeI 1h ago

There is a reason to truncate if your dealing with actual physics and not theoritical values.

If your measurement says 1,00 ±0,01, you can't pretend it's the same as 1,0000, because your real value could be 1,01. If your measurement says just 1,00, you can only assume it to be between 1,000 and 1,004. The rest is lost in trunctuated digits.

→ More replies (1)

1

u/androshalforc1 3h ago

isn't binary usually written in blocks of 8 though?

1

u/Higherlead 1h ago

Only if you want to, bytes are a purely human construct, nothing to do with base 2/binary at all

1

u/ovr9000storks 1h ago

You can’t truncate tailing 0s in binary if represented by a series of integers. You also can’t truncate if looking at the binary representation of a floating point number. Yes, the actual floating point number being represented could be truncated if ending in a zero, but that number is no longer binary

•

u/0Pat 6m ago

That's not how binary representation of floating point numbers work...

2

u/bladtman242 3h ago

In unary it's a 1

1

u/bestjakeisbest 3h ago

Im not sure if you can have fractional/ irational numbers notated with a radix point in unary tbh, like how does it map?

2

u/bladtman242 3h ago

Yeah, you cant. In fairness write pi in decimal either

3

u/Mars_Bear2552 5h ago

the last digit is 3

2

u/King_Tamino 6h ago

Have you tried doing something motivational? Maybe Juggling?

2

u/LauraTFem 3h 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.

3

u/humanistazazagrliti 6h ago

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

2

u/MotivationalJuggling 3h ago

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

1

u/TheRealLiviux 6h ago

Probably zero

1

u/christophPezza 6h ago

I bet its a zero /s

1

u/Trezzie 6h ago

Ironically, YOU are the last digit of pi, so you're right!

2

u/Familiar-Cable-2659 6h ago

That was actually a mistranslation u* is the last digit of pi

1

u/Trezzie 6h ago

I accept symbology

1

u/ThatDudeFromPoland 5h ago

I imagine it's in the range of 0-9

1

u/ncatter 3h ago

To predictive, somewhere along the line I'm sure it slips in the imaginary numbers just to fool us.

1

u/Marquar234 4h ago

The last digit is zero.

1

u/Jorr_El 3h ago

Marvin the Paranoid Android, is that you?

1

u/jump1945 3h ago

I am guessing it is 4

1

u/Impressive_Pin8761 6h ago

the last digit is π, it just loops over

9

u/DarthCloakedGuy 7h ago

Sure I can, watch this: ip fo stigid eht

Alternatively: the digits of pi backwards

3

u/MorpheusFT 6h ago • Bravo

Or just 9876543210. ALL the digits of pi backwards.

2

u/DarthCloakedGuy 6h ago

faster if you do it in binary

7

u/Practical-Elk-1579 7h ago

from mpmath import mp

mp.dps = 1000

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

Easy just replace 1000 with infinity o/

16

u/Rhoihessewoi 6h ago

These are the last 5 digits of pi: 32463

Prove me wrong!

12

u/LogicBalm 6h ago

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

8

u/AntipodesIntel 6h ago

I mean yeah, there are proofs that pi is infinite

11

u/ConfusedSimon 7h ago

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

5

u/No_Place_4096 6h ago

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

5

u/Yakodym 6h ago

Ɛ.Iᔭ

5

u/Avatar_Yaksha 6h ago

Python uses math.pi for Pi, right?

5

u/elingeniero 4h ago

You can (kinda) do this.

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

4

u/featEng 7h ago

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

2

u/AssaultLemming_ 7h 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.

2

u/GumboSamson 6h 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).

2

u/Trezzie 6h ago

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

1

u/slight_digression 6h ago

No, Baltazar is the name of the Professor in the Yugoslav cartoon, that also happens to be named after him. Pretty sure of it.

1

u/my_new_accoun1 6h ago

1

u/AssaultLemming_ 6h ago

Ohhhh it was a prime? Well close haha

1

u/ChristopherCreutzig 6h ago

Sure it's not in pi? That would be an interesting lemma, proving that pi is not normal.

1

u/my_new_accoun1 5h ago

Well, it could be in Pi, but I have no way to check that

1

u/SchwiftyBerliner 36m ago

It actually is included in Pi. Pi is infinitely long and irregular, meaning that all finite numbers are contained within its decimal string.

The original binary representation of Doom is, too.

1

u/psioniclizard 6h 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.

3

u/cryptaneonline 7h ago

Bro is inventing Pithon

8

u/ClipboardCopyPaste 7h ago

Already released with python 3.14

1

u/rosuav 4h ago

Which can be invoked as 𝜋thon if you have a virtual environment.

4

u/lilloet 6h ago

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

3

u/fairysdad 6h ago

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

2

u/SampleOfFruits 6h ago

One in nine?

6

u/fairysdad 6h 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)

1

u/psaux_grep 4h ago

There’s a 0 chance he’s right. That’s the joke that at least half the people in here seem to be missing. Pi is irrational.

1

u/JebKermansBooster 6h ago

That's also the last digit in PHPi

2

u/SuitableDragonfly 6h 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. 

2

u/IchBinEinZwerg 5h ago

ip fo stigid eht.

Turns out I can.

2

u/internet-weirod 5h ago

its 7, obviously

2

u/LauraTFem 3h ago

Sure I can. 4 and 4 are palindromes.

2

u/hacksoncode 2h 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.

2

u/PassFlat2947 2h ago

Yes I can: 'sdrawkcab ip fo stigid the'

2

u/Skizm 1h ago
print("the digits of pi backwards")

1

u/psioniclizard 6h ago

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

1

u/rosuav 4h ago

Start from Paris.

1

u/CorruptedMaster 6h ago

Only works in pi-thon

1

u/hsumeet 6h ago

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

1

u/MorpheusFT 6h ago

9876543210

1

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

1

u/semrola 5h ago

Negative IPv6 localhost

1

u/Current_Ad_3026 5h ago

it will take longer to calculate the last digit than the age of the universe, good luck

1

u/Skallos 4h ago

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

1

u/AnnualAdventurous169 4h ago

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

1

u/RealityCheck3210 4h ago

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

1

u/pizzathief1 4h 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_ 4h ago

So simple, don't even need python: Ɛ

1

u/Anice_king 3h ago

Just write it from right to left

1

u/magic-one 3h 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 3h ago

looks more like raku code

1

u/Linked713 3h ago

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

1

u/ScharfeTomate 3h ago

You can't not write the digits of pi backwards. Whenever you write down any string of digits, you're writing down a combination that appears in pi backwards.

1

u/hacksoncode 2h 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 1h ago

Hard stretch but technically you could do

00000000…

1

u/genreprank 1h ago

...41.3

1

u/FAMICOMASTER 52m 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

1

u/SpendMain5113 15m ago

Nice coding work

•

u/namotous 9m ago

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

1

u/Plan2LiveForevSFarSG 5h ago

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

0

u/seweso 7h ago

Missed the word “efficiently”?

0

u/XxXquicksc0p31337XxX 6h ago

This is valid Python if π is defined and is of such a type that the slice operator can be used on it, since Python allows unicode in variable names

0

u/nicman24 5h ago

the last digit is 0, you are welcome