• Shinji_Ikari [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    7 months ago

    Programming humor on reddit used to be excellent bits like this but then it devolved into new learners jumping straight to the irony they didn’t understand and flooded the sub with nonsense.

    I miss these bits.

    btw it does get easier

    import math
    def is_even(num):
        if num in [i for i in range(1000) if float(i)/2.0 == math.floor(float(i)/2.0)]:
            print("true")
        else:
            print("false")
    

    Obviously one would need to increase the range for bigger numbers but this code is optimized.

    • misophist@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      7 months ago

      This is confusing. I’m already using the iSeven API to determine if a number is 7. I’m getting a namespace collision error when I try to load this new API. Bug report filed.

  • neidu@feddit.nl
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    7 months ago

    My solution in perl back in the day when I was a teenage hobbyist who didn’t know about the modulus operator: Divide by 2 and use regex to check for a decimal point.

    if ($num / 2 =~ /\./) { return “odd” }
    else { return “even” }