this post was submitted on 04 Sep 2025
490 points (98.6% liked)

People Twitter

8103 readers
1293 users here now

People tweeting stuff. We allow tweets from anyone.

RULES:

  1. Mark NSFW content.
  2. No doxxing people.
  3. Must be a pic of the tweet or similar. No direct links to the tweet.
  4. No bullying or international politcs
  5. Be excellent to each other.
  6. Provide an archived link to the tweet (or similar) being shown if it's a major figure or a politician.

founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] kryptonianCodeMonkey@lemmy.world 9 points 1 day ago* (last edited 22 hours ago) (2 children)

Works for code too

import math

def multiply_bad(a:int, b:int) -> int:
    return a*b

def multiply_better(a:int, b:int) -> int:
    return (-1 if a<0 else 1)*(-1 if b<0 else 1)*int(math.sqrt(a*a*b*b))

def multiply_perfect(a:int, b:int) -> int:
    product = 0
    negative = False
    if a < 0:
        a = -1*a
        negative = not negative
    if b < 0:
        b = -1*b
        negative = not negative
    for i in range(a):
        for j in range(b):
            product += 1
    if negative:
         return -1*product
    return product
[–] sugar_in_your_tea@sh.itjust.works 1 points 4 hours ago* (last edited 2 hours ago) (1 children)

Missed opportunity for an obfuscated recursive solution.

[–] kryptonianCodeMonkey@lemmy.world 2 points 2 hours ago (1 children)

Damn you're right. I bet i could come up with a bullshit bitwise operator solution too

So many missed opportunities. 🙂

[–] MeThisGuy@feddit.nl 2 points 1 day ago (2 children)

care to explain this to a pleb in laymen's terms?

Basically, "why cross the street when you can circle the block 4 times while walking backwards and end up at the same spot"?

It's a joke, the less predictable way is just a far worse way to solve the problem, with a few faults sprinkled in.