• Shinji_Ikari [he/him]@hexbear.net
    link
    fedilink
    English
    arrow-up
    18
    ·
    edit-2
    1 year 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.

    • sloppy_diffuser
      link
      fedilink
      English
      arrow-up
      4
      ·
      1 year ago

      for i in itertools.count(): ... will count to infinity.

      Better make it into a dictionary so it’s O(1) complexity instead of O(n) while you’re at it.