An Interest In:
Web News this Week
- March 4, 2024
- March 3, 2024
- March 2, 2024
- March 1, 2024
- February 29, 2024
- February 28, 2024
- February 27, 2024
June 11, 2020 01:08 pm GMT
Original Link: https://dev.to/thepracticaldev/daily-challenge-257-halving-sum-41i0
Daily Challenge 257 - Halving Sum
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 [email protected] with your suggestions!
Original Link: https://dev.to/thepracticaldev/daily-challenge-257-halving-sum-41i0
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To