真理値表を作成するための準備 その2
2007/06/08
java
public class PrintCombination {
public PrintCombination() {
}
public static void main(String[] args) {
p(3);
}
public static void p(int n) {
int t = 1;
for (int i = 0; i < n; i++)
t = t * 2;
System.out.println("c:" + t);
Boolean[] b = new Boolean[n];
for (int i = 0; i < n; i++)
b[i] = false;
int pos = n - 1;
pp(b, pos);
}
public static void pp(Boolean[] bb, int pos) {
if (!(0 <= pos)) {
print(bb);
return;
}
bb[pos] = true;
pp(bb, pos - 1);
bb[pos] = false;
pp(bb, pos - 1);
}
public static void print(Boolean[] bs) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bs.length; i++)
builder.append(bs[i] ? "T" : "F").append(" ");
System.out.println(builder);
}
}
public PrintCombination() {
}
public static void main(String[] args) {
p(3);
}
public static void p(int n) {
int t = 1;
for (int i = 0; i < n; i++)
t = t * 2;
System.out.println("c:" + t);
Boolean[] b = new Boolean[n];
for (int i = 0; i < n; i++)
b[i] = false;
int pos = n - 1;
pp(b, pos);
}
public static void pp(Boolean[] bb, int pos) {
if (!(0 <= pos)) {
print(bb);
return;
}
bb[pos] = true;
pp(bb, pos - 1);
bb[pos] = false;
pp(bb, pos - 1);
}
public static void print(Boolean[] bs) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bs.length; i++)
builder.append(bs[i] ? "T" : "F").append(" ");
System.out.println(builder);
}
}
c:16
T T T T
F T T T
T F T T
F F T T
T T F T
F T F T
T F F T
F F F T
T T T F
F T T F
T F T F
F F T F
T T F F
F T F F
T F F F
F F F F
: