Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 3 months agoGood Use for AIi.imgur.comexternal-linkmessage-square24fedilinkarrow-up1390arrow-down17file-text
arrow-up1383arrow-down1external-linkGood Use for AIi.imgur.comPro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 3 months agomessage-square24fedilinkfile-text
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up1·edit-23 months agoWorks 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
minus-squareMeThisGuy@feddit.nllinkfedilinkarrow-up1·3 months agocare to explain this to a pleb in laymen’s terms?
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·3 months agoBasically, “why cross the street when you can circle the block 4 times while walking backwards and end up at the same spot”?
minus-squareUndercoverUlrikHD@programming.devlinkfedilinkarrow-up1·3 months agoIt’s a joke, the less predictable way is just a far worse way to solve the problem, with a few faults sprinkled in.
minus-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up1·edit-23 months agoMissed opportunity for an obfuscated recursive solution.
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·3 months agoDamn you’re right. I bet i could come up with a bullshit bitwise operator solution too
minus-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up1·3 months agoSo many missed opportunities. 🙂
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 productcare 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.
Missed opportunity for an obfuscated recursive solution.
Damn you’re right. I bet i could come up with a bullshit bitwise operator solution too
So many missed opportunities. 🙂