Gray code: Difference between revisions
Content added Content deleted
No edit summary |
(→{{header|OCaml}}: using bytes) |
||
Line 3,639: | Line 3,639: | ||
let bool_string len n = |
let bool_string len n = |
||
let s = |
let s = Bytes.make len '0' in |
||
let rec aux i n = |
let rec aux i n = |
||
if n land 1 = 1 then |
if n land 1 = 1 then Bytes.set s i '1'; |
||
if i <= 0 then s |
if i <= 0 then (Bytes.to_string s) |
||
else aux (pred i) (n lsr 1) |
else aux (pred i) (n lsr 1) |
||
in |
in |