Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 9 days agoGood Use for AIi.imgur.comimagemessage-square30fedilinkarrow-up1515arrow-down17file-text
arrow-up1508arrow-down1imageGood Use for AIi.imgur.comPro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 9 days agomessage-square30fedilinkfile-text
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up9·edit-28 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-squareMeThisGuy@feddit.nllinkfedilinkarrow-up2·8 days agocare to explain this to a pleb in laymen’s terms?
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up5·8 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·8 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.
minus-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up1·edit-27 days agoMissed opportunity for an obfuscated recursive solution.
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·7 days 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·7 days 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 product
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.
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. 🙂