The Belfry
  • Communities
  • Create Post
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 10 天前

Good Use for AI

i.imgur.com

message-square
30
fedilink
  • cross-posted to:
  • microblogmemes@lemmy.world
500

Good Use for AI

i.imgur.com

Pro@reddthat.com to People Twitter@sh.itjust.worksEnglish · 10 天前
message-square
30
fedilink
  • cross-posted to:
  • microblogmemes@lemmy.world

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

Pete Alex Harris— Mastodon.

  • kryptonianCodeMonkey@lemmy.world
    link
    fedilink
    arrow-up
    9
    ·
    edit-2
    10 天前

    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
      2
      ·
      10 天前

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

      • kryptonianCodeMonkey@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        10 天前

        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
        2
        ·
        10 天前

        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
      9 天前

      Missed opportunity for an obfuscated recursive solution.

      • kryptonianCodeMonkey@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        9 天前

        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
          ·
          9 天前

          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.
Visibility: Public
globe

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

  • 1.83K users / day
  • 4.58K users / week
  • 8.53K users / month
  • 19.4K users / 6 months
  • 1 local subscriber
  • 8.16K subscribers
  • 877 Posts
  • 24.1K Comments
  • Modlog
  • mods:
  • SendMeYourTaTas@sh.itjust.works
  • pelespirit@sh.itjust.works
  • BE: 0.19.5
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org