Value of a Logic Formula
formula is built by these rules, with no spaces:
tis true andfis false.!(A)is true when the formulaAis false.&(A,B,...)is true when every formula in the brackets is true.|(A,B,...)is true when at least one formula in the brackets is true.
The brackets of & and | hold one or more formulas, separated by commas. Return the value of formula as True or False.
Example 1
formula "&(t,|(f,t))"
returns true
The inner | is true because one of its parts is true. Then both parts of the & are true.
Example 2
formula "!(|(f,t))"
returns false
The | is true, so its negation is false.
Example 3
formula "&(t,t,f,t)"
returns false
An & with a false part is false, whatever the other parts are.
Constraints
1 <= len(formula) <= 80formulafollows the rules above
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Close Every BracketBeginner
- Crate PileBeginner
- Dead-End DrivewayBeginner
- Elevator TripsBeginner
- Flip the PancakesBeginner
- Last In, First OutBeginner
- Notes on the BoardBeginner
- One-Bay Car WashBeginner