← Quiz: Simplifying CFGs and CNF: all 10 questions
Quiz: Simplifying CFGs and CNF · Question 5 of 10
What does this print? (code)
What does this print?
from itertools import product
nullable = {"A"}
body = ("a", "A", "A")
choices = [[(s,), ()] if s in nullable else [(s,)] for s in body]
bodies = {tuple(s for part in pick for s in part) for pick in product(*choices)}
print(len(bodies))
- A.2
- B.3
- C.4
- D.8
Answer & explanation
Correct answer: 3
The four choices give a A A, a A, a A again and a. Duplicates collapse, leaving 3 different bodies.
Can you get the rest right without peeking?
Take the timed Quiz: Simplifying CFGs and CNF quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →