Skip to content

Instantly share code, notes, and snippets.

@u8sand
Last active May 10, 2016 11:53
Show Gist options
  • Save u8sand/8c78ed0aeb1b198d37ff to your computer and use it in GitHub Desktop.
Save u8sand/8c78ed0aeb1b198d37ff to your computer and use it in GitHub Desktop.
Generate simple n-bit truth tables
''' Generate a truth table '''
from itertools import product
import sys
args = sys.argv[1:]
if args!=[]:
bits = int(args[0])
sep1 = '\t' if len(args)<=1 else args[1]
sep2 = '\n' if len(args)<=2 else args[2]
print(sep2.join([sep1.join(map(str,l)) for l in product(*[(0,1)]*bits)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment