Marius’s Lemmy
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 5 个月前

Infallible Code

lemmy.ml

message-square
162
link
fedilink
462

Infallible Code

lemmy.ml

Destide@feddit.uk to Programmer Humor@lemmy.mlEnglish · 5 个月前
message-square
162
link
fedilink
  • redxef@feddit.org
    link
    fedilink
    arrow-up
    38
    ·
    5 个月前
    def is_even(n: int) -> bool:
        if n < 0:
            return is_even(-n)
        r = True
        for _ in range(n):
            r = not r
        return r
    
    • OddMinus1@sh.itjust.works
      link
      fedilink
      arrow-up
      4
      ·
      5 个月前

      Could also be done recursive, I guess?

      boolean isEven(int n) {
        if (n == 0) {
          return true;
        } else {
          return !isEven(Math.abs(n - 1));
        }
      }
      
      • ⛓️‍💥@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        5 个月前

        deleted by creator

    • dragonlobster@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      5 个月前

      He loves me, he loves me not

    • vandsjov@feddit.dk
      link
      fedilink
      arrow-up
      1
      ·
      5 个月前

      No, no, I would convert the number to a string and just check the last char to see if it was even or not.

Programmer Humor@lemmy.ml

programmerhumor@lemmy.ml

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: !programmerhumor@lemmy.ml

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.
Visibility: Public
globe

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

  • 366 users / day
  • 860 users / week
  • 2.26K users / month
  • 6.23K users / 6 months
  • 1 local subscriber
  • 39.5K subscribers
  • 1.97K Posts
  • 35.8K Comments
  • Modlog
  • mods:
  • AgreeableLandscape@lemmy.ml
  • cat_programmer@lemmy.ml
  • UI: unknown version
  • BE: 0.19.13
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code
  • join-lemmy.org