• + 2 comments

    here the same code but with comments and a YT link, you're welcome future coders

    • + 0 comments

      /* import java.util.BitSet; //this code compares two bitset arrays of 1's and 0's import java.util.Scanner;

      public class javaBitsetwork {
      
          public static void main(String[] args) {
              Scanner scan = new Scanner(System.in);
              int n = scan.nextInt();                    //asks for size of each bitset array
              int m = scan.nextInt();                   //asks for number of operations you're gonna give it for the bitsets
      
              BitSet b1 = new BitSet(n);              //first bitset array
              BitSet b2 = new BitSet(n);              //second bitset array
              BitSet[] bitset = new BitSet[3];        //larger bitset array that the first two are going into (making an "x,y" 2D array)
      
              bitset[1] = b1;                      //puts first bitset array in larger bitset array
              bitset[2] = b2;
      
              while ( 0 < m-- ) {                 //performs the operations
                  String op = scan.next();
                  int x = scan.nextInt();
                  int y = scan.nextInt();
      
                      switch (op) {
                              case "AND":                          //everything is 0 so everything is 0
                                  bitset[x].and(bitset[y]);       //https://www.youtube.com/watch?v=4hhWVy8VtxY
                                  break;
                              case "SET":
                                  bitset[x].set(y);               //this sets x index of the big array (so small array 1), with y index of 
                                                                   //the small array to true (any value above 0 makes it true)
                                  break;
                              case "FLIP":                    //flips a bit from false to true and vice versa I assume
                                  bitset[x].flip(y);
                                  break;  
                              case "OR":                        //if one is true then they're both true
                                  bitset[x].or(bitset[y]);
                                  break;             
                              case "XOR":                     //if one is false then they're both false
                                  bitset[x].xor(bitset[y]);  
      
                      }
      
                System.out.println("this is x:" + x + "  b1: " + b1+ "  b2: " + b2);
                System.out.printf("%d %d%n", b1.cardinality(), b2.cardinality());  //prints out the "cardinality" aka the number of elements..
                                                                                     //in each set 
              }
              scan.close();
          }
      }*/
      
    • + 0 comments

      /* import java.util.BitSet; //this code compares two bitset arrays of 1's and 0's import java.util.Scanner;

      public class javaBitsetwork {
      
          public static void main(String[] args) {
              Scanner scan = new Scanner(System.in);
              int n = scan.nextInt();                    //asks for size of each bitset array
              int m = scan.nextInt();                   //asks for number of operations you're gonna give it for the bitsets
      
              BitSet b1 = new BitSet(n);              //first bitset array
              BitSet b2 = new BitSet(n);              //second bitset array
              BitSet[] bitset = new BitSet[3];        //larger bitset array that the first two are going into (making an "x,y" 2D array)
      
              bitset[1] = b1;                      //puts first bitset array in larger bitset array
              bitset[2] = b2;
      
              while ( 0 < m-- ) {                 //performs the operations
                  String op = scan.next();
                  int x = scan.nextInt();
                  int y = scan.nextInt();
      
                      switch (op) {
                              case "AND":                          //everything is 0 so everything is 0
                                  bitset[x].and(bitset[y]);       //https://www.youtube.com/watch?v=4hhWVy8VtxY
                                  break;
                              case "SET":
                                  bitset[x].set(y);               //this sets x index of the big array (so small array 1), with y index of 
                                                                   //the small array to true (any value above 0 makes it true)
                                  break;
                              case "FLIP":                    //flips a bit from false to true and vice versa I assume
                                  bitset[x].flip(y);
                                  break;  
                              case "OR":                        //if one is true then they're both true
                                  bitset[x].or(bitset[y]);
                                  break;             
                              case "XOR":                     //if one is false then they're both false
                                  bitset[x].xor(bitset[y]);  
      
                      }
      
                System.out.println("this is x:" + x + "  b1: " + b1+ "  b2: " + b2);
                System.out.printf("%d %d%n", b1.cardinality(), b2.cardinality());  //prints out the "cardinality" aka the number of elements..
                                                                                     //in each set 
              }
              scan.close();
          }
      }*/