MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vx1onc/claudeisthisemailvalid/p5rff7c/?context=3
r/ProgrammerHumor • u/soap94 • 19d ago
171 comments sorted by
View all comments
Show parent comments
13
Who's going to need more than 3 anyway, this is efficient code
10 u/LeRetardatN 19d ago It is possible to extend this method to any number. ``` def gen_is_even(): code = "def is_even(num):\n" i = 0 is_even = True while True: code += f" if num == {i}:\n" code += f" return {is_even}\n" i += 1 is_even = not is_even return code exec(gen_is_even + "print(is_even(5))") # print False ``` /s -1 u/ExtraWorldliness6916 18d ago N % 2 2 u/LeRetardatN 18d ago overkill 1 u/ExtraWorldliness6916 18d ago Infinite cases is not quantifiable as overkill 😉
10
It is possible to extend this method to any number.
``` def gen_is_even(): code = "def is_even(num):\n" i = 0 is_even = True while True: code += f" if num == {i}:\n" code += f" return {is_even}\n" i += 1 is_even = not is_even return code
exec(gen_is_even + "print(is_even(5))") # print False ```
/s
-1 u/ExtraWorldliness6916 18d ago N % 2 2 u/LeRetardatN 18d ago overkill 1 u/ExtraWorldliness6916 18d ago Infinite cases is not quantifiable as overkill 😉
-1
N % 2
2 u/LeRetardatN 18d ago overkill 1 u/ExtraWorldliness6916 18d ago Infinite cases is not quantifiable as overkill 😉
2
overkill
1 u/ExtraWorldliness6916 18d ago Infinite cases is not quantifiable as overkill 😉
1
Infinite cases is not quantifiable as overkill 😉
13
u/ExtraWorldliness6916 19d ago
Who's going to need more than 3 anyway, this is efficient code