26
A positive integer can be diluted by inserting a 0 between two bits in its binary expansion. This means that an n-bit number has n-1 dilutions, which are not necessarily all distinct.
For example, for 12 (or 1100 in binary), the dilutions are
11000 = 24
^
11000 = 24
^
10100 = 20
^
In this challenge, we're going to be taking the sum of all the dilutions, exclusive of the original number. For 12, taking the sum of 24, 24, 20 results in 68, so 68 should be the output for 12.
Challenge
Given a positive integer n > 1 as input, output/return the diluted sum as explained above.
Examples
in out
--- ---
2 4
3 5
7 24
12 68
333 5128
512 9216
Rules
- The input and output can be assumed to fit in your language's native integer type.
- The input and output can be given in any convenient format.
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Does "any convenient format" include a binary string? – Shaggy – 2018-01-29T15:40:31.230
1@Shaggy "Any convenient format" is intended to be inclusive of methods of input/output, not format. As such, I'm going to say no, you must take input as an integer or a string representing that integer. – AdmBorkBork – 2018-01-29T16:02:17.307
Nice challenge! – Manish Kundu – 2018-01-29T17:14:16.417
1
This sequence is currently (30 Jan 2018) not in the OEIS
– Giuseppe – 2018-01-30T19:51:51.133