Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 14 days agoGood Use for AIi.imgur.comimagemessage-square27linkfedilinkarrow-up1501arrow-down17file-textcross-posted to: microblogmemes@lemmy.world
arrow-up1494arrow-down1imageGood Use for AIi.imgur.comPro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 14 days agomessage-square27linkfedilinkfile-textcross-posted to: microblogmemes@lemmy.world
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up8·edit-213 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-212 days agoMissed opportunity for an obfuscated recursive solution.
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·12 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·12 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
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. 🙂