Sorting a list of zeros and ones.

  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    List Sorting
AI Thread Summary
The discussion revolves around generating a truth table from an initial array of zeros, specifically for a scenario where there are n-2 columns and 2^(n-2) rows. The user is seeking help on how to implement a loop that fills in the array with binary values, transitioning from zeros to ones in a structured manner. The desired output is a systematic arrangement of binary combinations, resembling a truth table. Suggestions include using nested loops with specific conditions to manage the transitions, though some participants recommend simpler methods, such as using a single loop with bit manipulation techniques. The urgency of the request is emphasized due to an upcoming exam.
MathematicalPhysicist
Science Advisor
Gold Member
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.
 
Technology news 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
... . . . .
    . . . .
    . . . .
?
 
Is there some particular reason you need to do this with nested for loops and complicated conditions? There are many simpler approaches.

- Warren
 
yes job, something like that.


chroot, iv'e learned loops, so i guess this is the way i shouldv'e solved it.

thanks anyway.
 
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
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top