Created
January 28, 2017 20:32
-
-
Save bschlenk/f704ccccd2da25a33cbf75cd2520ec30 to your computer and use it in GitHub Desktop.
Generate all possible truth table combinations for the given number of inputs. Wrote for students in logic class.
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
#!/usr/bin/env python | |
import sys | |
if len(sys.argv) != 2: | |
print "usage: %s <number of inputs>" % sys.argv[0] | |
sys.exit(1) | |
inputs = int(sys.argv[1]) | |
rows = 2 ** inputs | |
for x in range(rows): | |
print bin(x)[2:].rjust(inputs, '0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment