this post was submitted on 22 Oct 2023
372 points (100.0% liked)

Programmer Humor

853 readers
2 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] kewko@lemdro.id 20 points 1 year ago (2 children)

Mathematician 2 kinda blew my mind, kinda obvious, just can't believe I was never taught or thought about it.

[–] mac@lemm.ee 3 points 1 year ago (1 children)

Lost me when it used Math.abs after calling math.max a their

[–] MBM@lemmings.world 3 points 1 year ago

Math.Sqrt((x-y) * (x-y)) (I've actually seen someone use this)

[–] Artyom@lemm.ee 2 points 1 year ago (1 children)

I've been staring at it for 10 minutes and I'm still not convinced it works.

[–] uberrice@feddit.de 2 points 1 year ago

Simple, really. Abs(x-y) is the difference between the two numbers, absolute, so positive value. So, adding abs(x-y) to the smaller of the two numbers turns it into the bigger number. Plus the bigger number, now you have 2 times the bigger number