Skip to main content
added 4 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 4242 41 bytes

≔E⮌↨N²…1ιθF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ≔⁻I⮌↨N²0θF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ 

Try it online!Try it online! Link is to verbose version of code. Supports numbers from 1 to 18446744073709551615. Explanation:

≔E⮌↨N²…1ιθ≔⁻I⮌↨N²0θ 

Convert the input to a list of 1s and empty strings according to the reverse of its binary representation.

F24HBSI 

Loop over the additional possible "digits".

≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθ 

Group the existing digit blocks into pairs, then for each pair, create a new digit block by removing any second part if it is zero, or making it the empty string if it is one, switching the parts, and joining on the next digit.

θ 

Output the final result.

Charcoal, 42 bytes

≔E⮌↨N²…1ιθF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ 

Try it online! Link is to verbose version of code. Supports numbers from 1 to 18446744073709551615. Explanation:

≔E⮌↨N²…1ιθ 

Convert the input to a list of 1s and empty strings according to the reverse of its binary representation.

F24HBSI 

Loop over the additional possible "digits".

≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθ 

Group the existing digit blocks into pairs, then for each pair, create a new digit block by removing any second part if it is zero, or making it the empty string if it is one, switching the parts, and joining on the next digit.

θ 

Output the final result.

Charcoal, 42 41 bytes

≔⁻I⮌↨N²0θF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ 

Try it online! Link is to verbose version of code. Supports numbers from 1 to 18446744073709551615. Explanation:

≔⁻I⮌↨N²0θ 

Convert the input to a list of 1s and empty strings according to the reverse of its binary representation.

F24HBSI 

Loop over the additional possible "digits".

≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθ 

Group the existing digit blocks into pairs, then for each pair, create a new digit block by removing any second part if it is zero, or making it the empty string if it is one, switching the parts, and joining on the next digit.

θ 

Output the final result.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 42 bytes

≔E⮌↨N²…1ιθF24HBSI≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθθ 

Try it online! Link is to verbose version of code. Supports numbers from 1 to 18446744073709551615. Explanation:

≔E⮌↨N²…1ιθ 

Convert the input to a list of 1s and empty strings according to the reverse of its binary representation.

F24HBSI 

Loop over the additional possible "digits".

≔E⪪θ²⪫⮌EΦκ∨μ¬ν⎇∧ν⁼μ1ωμιθ 

Group the existing digit blocks into pairs, then for each pair, create a new digit block by removing any second part if it is zero, or making it the empty string if it is one, switching the parts, and joining on the next digit.

θ 

Output the final result.