Group Abstract Group Abstract

Message Boards Message Boards

[?] Rearrange the following binary data?

6 Replies

Is it this what you really want? :

IntegerDigits[#, 2, 4] & /@ SortBy[Range[0, 15], EvenQ]

Or you can generalize:

oddEvenDigits[max_Integer] := IntegerDigits[#, 2, Ceiling[Log[max]/Log[2.]]] & /@ SortBy[Range[0, max], EvenQ]
POSTED BY: Henrik Schachner

Could join evens to odds, as below.

qEvenOdd = Join[q[[2 ;; -1 ;; 2]], q[[1 ;; -2 ;; 2]]]

(* {{0, 0, 0, 1}, {0, 0, 1, 1}, {0, 1, 0, 1}, {0, 1, 1, 1}, {1, 0, 0, 
  1}, {1, 0, 1, 1}, {1, 1, 0, 1}, {1, 1, 1, 1}, {0, 0, 0, 0}, {0, 0, 
  1, 0}, {0, 1, 0, 0}, {0, 1, 1, 0}, {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 
  1, 0, 0}, {1, 1, 1, 0}} *)
POSTED BY: Daniel Lichtblau

Thanks very much Henrik! I appreciate your time. This is exactly what I did when I regarded your formulation as (max - 1), because you get for instance oddEvenDigits[31] if n = 5.

oddEvenDigits[15]
    (* Out:   {{0,0,0,1},{0,0,1,1},{0,1,0,1},{0,1,1,1},{1,0,0,1},{1,0,1,1},{1,1,0,1}\
    ,{1,1,1,1},{0,0,0,0},{0,0,1,0},{0,1,0,0},{0,1,1,0},{1,0,0,0},{1,0,1,0}\
    ,{1,1,0,0},{1,1,1,0}}   *)

... I did not regard max (i.e. the argument of my oddEvenDigits) as a power of 2. It can be just any number.

For the case of "all combination" write

oddEvenDigits[2^n - 1]
POSTED BY: Henrik Schachner

Excellent Henrik! But I think the last part is: IntegerDigits[#, 2, Ceiling[Log[max]/Log[2.]]] & /@ SortBy[Range[0, max - 1], EvenQ]; otherwise it adds one more with zeros.

Thanks very much Daniel!!! I read very often your posts and comments and appreciate it.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard