Skip to content

Instantly share code, notes, and snippets.

@offlinemark
Last active August 29, 2015 13:58
Show Gist options
  • Save offlinemark/10041138 to your computer and use it in GitHub Desktop.
Save offlinemark/10041138 to your computer and use it in GitHub Desktop.
Generates the necessary flip flop inputs for a finite state machine with 3 bit state encodings
#!/usr/bin/env python
def ff(a, b):
if a == 0 and b == 0:
print '0 X',
elif a == 0 and b == 1:
print '1 X',
elif a == 1 and b == 0:
print 'X 1',
elif a == 1 and b == 1:
print 'X 0',
present = [(0, 0, 0), (0, 0, 0), (0, 0, 1),
(0, 0, 1), (0, 1, 0), (0, 1, 0),
(0, 1, 1), (0, 1, 1), (1, 0, 0), (1, 0, 0)
]
next = [(0, 1, 1), (1, 0, 0), (0, 0, 1),
(1, 0, 0), (0, 1, 0), (0, 0, 0),
(0, 0, 1), (0, 1, 0), (0, 1, 0), (0, 1, 1)
]
bag = zip(present, next)
for each in bag:
for i in range(3):
ff(each[0][i], each[1][i])
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment