Created
March 6, 2022 07:07
-
-
Save irfanabduhu/562565614d1a7a042f54b0332514af54 to your computer and use it in GitHub Desktop.
Boolean Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
void helper(int n, int i, vector<bool> res); | |
void binary(int n) { | |
vector<bool> res(n); | |
helper(n, 0, res); | |
} | |
void helper(int n, int i, vector<bool> res) { | |
if (i == n) { | |
for (int k = 0; k < res.size(); k++) | |
cout << res[k] << " "; | |
cout << endl; | |
} else { | |
res[i] = false; | |
helper(n, i + 1, res); | |
res[i] = true; | |
helper(n, i + 1, res); | |
} | |
} | |
int main(void) { | |
int n; | |
cin >> n; | |
binary(n); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def boolean_table(n): | |
flags = [0] * n | |
def helper(n, i, flags): | |
if i == n: | |
print(flags) | |
else: | |
flags[i] = 0 | |
helper(n, i + 1, flags) | |
flags[i] = 1 | |
helper(n, i + 1, flags) | |
helper(n, 0, flags) | |
n = int(input("Number of boolean variables: ")) | |
boolean_table(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean_table(n): | |
flags <- boolean array of size n | |
helper(n, 0, flags) | |
helper(n, i, flags): | |
if i == n: | |
print flags | |
else: | |
flags[i] <- False | |
helper(n, i + 1, flags) | |
flags[i] <- True | |
helper(n, i + 1, flags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment