the.bay.news

Decompose positive integer into 2^p+m

Julia Programming Language
Decompose positive integer into 2^p+m
This is a bit-wrangling question: I would like to decompose a positive integer x into 2^p+m, for the highest p such that m \ge 0. Expected output: julia> for i in 1:7 println(i => decompose(i)) end 1 => (0, 0) 2 => (1, 0) 3 => (1, 1) 4 => (2, 0) 5 => (2, 1) 6 => (2, 2) 7 => (2, 3) an example implementation, but it uses an internal function: """ Let `p` be the highest integer such that ``x = 2^p + m`` and `m ≥ 0`. Return `p, m`. """ function decompose(x::Integer) @assert x > ...

0 comments

Sign in to join the discussion — your thebay.events account works here.

No comments yet.