Logical Functions: AND and OR
InterviewTime limit2sMemory limit256 MB
Check each submitted weight and bias by testing all four binary inputs and report whether the neuron matches the requested AND or OR gate.
- Level
Easy1 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
A neuron node takes two inputs, and . Each input is 0 or 1. Every input carries its own weight: belongs to and belongs to . The node also has a bias , which moves the point where the node turns on.
The node first computes the weighted sum
and then applies a step activation function. The output is 1 when , and 0 otherwise.

Figure 1. Neuron node
A machine learning class asked its students to pick weights and a bias so that one neuron node computes a logical AND, or a logical OR. You are the teaching assistant, so you have to check the submissions. A submission is correct when the output of the node equals the value of the requested logical function for all four combinations of and .
Input
The first line contains the number of test cases ().
Each of the next lines describes one submission: a word, then three real numbers , and , separated by whitespace. The word is either AND or OR and names the logical function that submission has to compute. and are the weights () and is the bias (). The numbers may contain a decimal point, and two tokens may be separated by more than one space.
Output
Print one line for each test case, in input order. Print true when the node computes the requested logical function for all four combinations of and , and false otherwise. Print both words in lowercase and without quotes.