index | submit | rank | book

bool-calc – Boolean calculator

Write a program that reads several boolean operations and prints their result.

Input will consist of several lines each containing a boolean operation. This operation may be unary, in this case the input line will contain the word not followed by a boolean p. This operation may be binary, in this case the input line will contain a boolean p, an operator x and a boolean q. Input tokens are separated by a single space. Booleans p and q are either of the strings true or false and the operator x is either of the strings and, or, xor or implies. Output should contain a line with the result of the given input operation.

Example input

true and false
false or true
not true
true xor true
true implies true

Example output

false
true
false
false
true

Scoring

try first: bool-and-or bool-not

try next: set-member

index | submit | rank | book

Copyright © 2020-2021 Rudy Matela
All rights reserved