Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 2 days agoGood Use for AIi.imgur.comimagemessage-square30linkfedilinkarrow-up1507arrow-down17file-text
arrow-up1500arrow-down1imageGood Use for AIi.imgur.comPro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 2 days agomessage-square30linkfedilinkfile-text
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up9·edit-22 days 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-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up1·edit-220 hours agoMissed opportunity for an obfuscated recursive solution.
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·21 hours 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·20 hours agoSo many missed opportunities. 🙂
minus-squareMeThisGuy@feddit.nllinkfedilinkarrow-up2·2 days agocare to explain this to a pleb in laymen’s terms?
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up5·2 days 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-up2·2 days agoIt’s a joke, the less predictable way is just a far worse way to solve the problem, with a few faults sprinkled in.
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
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. 🙂
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.