Sorting a list of zeros and ones.

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    List Sorting
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
Messages
4,662
Reaction score
372
Assume i have an initial list of n-2 columns and 2^(n-2) rows, where initially:
all the entries are zero.
i wnt to sort it out that eveantually we'll get a truth table for this.
i.e if we have n-2=2 rows and 4 columns, then:
Code:
0 0
1 0
0 1
1 1
obvously we have here a jump first we initialise the array to give us everywhere zero, afterwards i need to insert via a loop the entries of 1, i.e in the first column it should be changing the zeros in a[1][1] and a[3][1] i.e we have a jump of two places and in the next column a jump of three places, but i don't know how to write it in the loop condition, any thoughts?
the exam is tommorow, so your help would be tremendous for my success, thanks in advance.
 
on Phys.org
You mean you want to generate something like this:
Code:
... 0 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
... 1 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
... . . . .
    . . . .
    . . . .
?
 
If I were doing it, I'd just use a single for loop that increments a counter. To extract each bit from the counter, I'd use a set of masks, one for each bit.

- Warren