Lemmy.eus
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 3 months ago

Good Use for AI

i.imgur.com

external-link
message-square
24
fedilink
383
external-link

Good Use for AI

i.imgur.com

Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 3 months ago
message-square
24
fedilink

cross-posted from: https://reddthat.com/post/49348996

Pete Alex Harris— Mastodon.

  • kryptonianCodeMonkey@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    3 months ago

    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
    • MeThisGuy@feddit.nl
      link
      fedilink
      arrow-up
      1
      ·
      3 months ago

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

      • kryptonianCodeMonkey@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        3 months ago

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

      • UndercoverUlrikHD@programming.dev
        link
        fedilink
        arrow-up
        1
        ·
        3 months ago

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

    • sugar_in_your_tea@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      3 months ago

      Missed opportunity for an obfuscated recursive solution.

      • kryptonianCodeMonkey@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        3 months ago

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

        • sugar_in_your_tea@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          3 months ago

          So many missed opportunities. 🙂

People Twitter@sh.itjust.works

whitepeopletwitter@sh.itjust.works

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !whitepeopletwitter@sh.itjust.works

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. Archive.is the best way.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 1.02K users / day
  • 4.14K users / week
  • 9.26K users / month
  • 16.7K users / 6 months
  • 1 local subscriber
  • 8.58K subscribers
  • 1.08K Posts
  • 31.7K Comments
  • Modlog
  • mods:
  • SendMeYourTaTas@sh.itjust.works
  • pelespirit@sh.itjust.works
  • BE: 0.19.7
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org