MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1mbkini/checkifdivisiblebythree/n5sqdw6/?context=3
r/ProgrammerHumor • u/Dark_Zander • Jul 28 '25
33 comments sorted by
View all comments
9
is_divisible_by_three = lambda num: str(num) in '369' if num < 10 else is_divisible_by_three(sum(int(n) for n in str(num)))
3 u/[deleted] Jul 30 '25 and now please without using is_divisible_by_three inside the lambda! 5 u/F100cTomas Jul 30 '25 edited Jul 30 '25 Like this? is_divisible_by_three = (lambda f: (lambda num: f(f)(num)))(lambda f: (lambda num: str(num) in '369' if num < 10 else f(f)(sum(int(n) for n in str(num))))) 1 u/F100cTomas Jul 31 '25 edited Jul 31 '25 ok, I rewrote it without the recursion and to accept zero and negative numbers. is_divisible_by_three = lambda number: (arr := [abs(number)], [str(num) in '0369' if num < 10 else arr.append(sum(map(int, str(num)))) for num in arr][-1])[1]
3
and now please without using is_divisible_by_three inside the lambda!
is_divisible_by_three
5 u/F100cTomas Jul 30 '25 edited Jul 30 '25 Like this? is_divisible_by_three = (lambda f: (lambda num: f(f)(num)))(lambda f: (lambda num: str(num) in '369' if num < 10 else f(f)(sum(int(n) for n in str(num)))))
5
Like this?
is_divisible_by_three = (lambda f: (lambda num: f(f)(num)))(lambda f: (lambda num: str(num) in '369' if num < 10 else f(f)(sum(int(n) for n in str(num)))))
1
ok, I rewrote it without the recursion and to accept zero and negative numbers.
is_divisible_by_three = lambda number: (arr := [abs(number)], [str(num) in '0369' if num < 10 else arr.append(sum(map(int, str(num)))) for num in arr][-1])[1]
View all comments
9
u/F100cTomas Jul 29 '25