Given a positive integer n, calculate the following sum:
n + n/2 + n/4 + n/8 + ...
All elements of the sum are the results of integer division. Continue dividing the number until you reach a decimal (no decimals allowed in final answer).
Example
25 => 25 + 12 + 6 + 3 + 1 = 47
Tests
halvingSum(25)
halvingSum(127)
This challenge comes from Belia on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!