DEV Community

Discussion on: Daily Challenge #257 - Halving Sum

Collapse
 
vidit1999 profile image
Vidit Sarkar

Here is a Python solution,


halvingSum = lambda n : n and (n + halvingSum(n >> 1))

print(halvingSum(25)) # output -> 47
print(halvingSum(127)) # output -> 247