Problem 61138. Apply the planing transform to natural numbers
Claude Lenormand’s planing (or raboter, in French) transform removes one element from each run in a sequence; that is, imagine applying a carpenter’s plane to each run and shaving off a number. If the original sequence is
1, 1, 2, 3, 3, 3, 4, 4, 5, 5, 5, 5, 5, 5, 6, 7, 7
Then the transformed sequence would be
1, 3, 3, 4, 5, 5, 5, 5, 5, 7
Let’s apply this transform to natural numbers by writing a number in binary, planing 1s and 0s from the runs in the binary representation, and converting back to decimal. If an empty string results from the planing, then set the result to zero. For example, the number 14 has the binary representation 1110. The transform removes one 1 and one (i.e., the only) 0 to leave 11, which has the decimal representation 3. Other examples:
- 2 is 10 in binary, which transforms to the empty string, so we set the result to zero.
- 4 is 100 in binary, which transforms to 0, which is 0 in decimal
- 13 is 1101 in binary, which transforms to 1, which is 1 in decimal
- 27 is 11011 in binary, which transforms to 11, which is 3 in decimal
- 900 is 1110000100 in binary, which transforms to 110000, which is 48 in decimal
Write a function to apply the planing transform to natural numbers.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers4
Suggested Problems
More from this Author316
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!