The Scenario: You have a storage bin called Inventory that starts with 10 items. You process a list of delivery tickets one by one: [+5, -12, +8, -2].
Rule A: If a ticket is positive, add that many items to the Inventory.
Rule B: If a ticket is negative, subtract that many items, but only if the Inventory has enough. If there aren't enough items, ignore the ticket entirely.
Question: What is the final number of items in the Inventory after all four tickets are processed?
21
The Scenario: You have a penny bank that starts with 5 pennies. You decide to add 3 pennies every day. You have a rule: "Keep adding pennies as long as the total is less than 15."
Question:
How many days will you add pennies?
What is the final number of pennies in the bank when you stop?
4 days and 17 pennies
Scenario: You are deciding how to get to work based on the weather and your bike's condition.
Condition A: If it is raining, you take the bus.
Condition B: If it is not raining, but your bike has a flat tire, you take the bus.
Condition C: If it is not raining and your bike is in good shape, you ride your bike.
Question: It is a beautiful, sunny day, but you notice a nail in your bike tire. How are you getting to work?
The Bus
The Idea: You want to save electricity by creating a smart light for your front porch.
Logic: The system checks a light sensor every minute. If the sensor detects "Dark," the porch light turns on. Else, the light turns off.
The Problem: On the first night, the light begins flashing on and off rapidly every minute like a strobe light. What is the flaw in this logic?
The Feedback Loop
Question 1 (Easy): Concept: Variables and Constants In logic, we use "containers" to hold information.
A Variable is a container where the value can change (like your age).
A Constant is a container where the value stays the same forever (like the number of hours in a day).
Question: You are designing an app for a pizza restaurant. You need to store three pieces of information:
The Customer’s Name.
The Price of a Large Pizza (which never changes).
The Number of Toppings the customer chooses.
Which of these are Variables, and which is a Constant?
Variables: Name, Number of Toppings. Constant: Pizza Price.
The Scenario: You start with the word "SPACE". You must apply these three rules to every letter, starting from the left:
Skip the first letter entirely.
For the next letter, replace it with the letter that comes two places after it in the alphabet (e.g., A becomes C).
For the letter after that, remove it from the word entirely.
Repeat steps 2 and 3 until you reach the end of the word.
Question: What is the final "word" (or string of letters) left at the end?
SCC
The Scenario: A climber starts at the bottom of a 10-step staircase (Step 0). Their goal is to reach Step 10. They follow these rules for every "turn" until they reach or pass Step 10:
Step A: Move up 2 steps.
Step B: If the step they are currently standing on is a multiple of 3 (like 3, 6, or 9), they must slide back 1 step.
Step C: Check if they are at or above Step 10. If not, start the next turn.
Question: How many "turns" does it take for the climber to reach Step 10? List the step they are on at the end of each turn.
6 turns 2, 4, 5, 7, 8, 10
Scenario: A high-security building has a specific entry protocol for visitors.
Rule 1: If a visitor has a "Gold" badge, they can enter the vault.
Rule 2: If they do not have a "Gold" badge, but they have a "Silver" badge and a signed escort form, they can enter the vault.
Rule 3: If they have a "Silver" badge but no form, they must stay in the lobby.
Rule 4: In all other cases, the visitor must leave the building.
Question: A visitor arrives with a Silver badge. They realized they left their signed escort form in their car. According to the rules, what must this visitor do?
Stay in the lobby
The Idea: An online store wants to reward loyal customers without losing too much money. They decide to offer two coupons, but they don't want them used at the same time.
Logic: * If a customer enters the "LUCKY10" code, take 10% off the total.
Else if the customer enters the "WELCOME5" code, take $5 off the total.
Else, charge the full price.
The Problem: A frustrated customer has both codes. They want to use the $5 discount because they are only buying a $10 item (which is a better deal than 10% off). However, every time they type in both codes or try to switch them, the system only gives them the 10% discount. What is wrong with how the rules are ordered?
Priority Conflict
Concept: Boolean Operators (AND vs. OR) Logical conditions often rely on "Operators" to decide if a statement is True or False.
AND: Requires all conditions to be true.
OR: Requires at least one condition to be true.
Question: A smart home security system is programmed with the following rule:
"Trigger the alarm if (The Front Door is Open AND the Security Code is NOT entered) OR (The Glass Break Sensor is triggered)."
The Front Door is Closed, the Security Code has NOT been entered, and a ball accidentally breaks the window, triggering the Glass Break Sensor. Does the alarm go off? Explain why using the vocabulary words.
Yes, the alarm goes off.
The Scenario: A robot is on a grid at position (0, 0). It is given a "Move Command": Repeat 3 times: [Step Right, Step Up]. However, a "Global Interruption" rule is active:
The Interruption: Every time the robot's Up position is an even number (like 0 or 2), it must take one extra Step Right immediately after its normal movement.
Question: Trace the robot's journey. What is its final coordinate (Right, Up) after the "Repeat 3" command is finished?
6, 3
The Scenario: A librarian is checking 3 shelves. Each shelf has 4 books. The librarian must follow this "Nested Routine":
Outer Loop: Move to the next shelf (Shelf 1, then 2, then 3).
Inner Loop: For every book on that shelf, check its condition.
If it is the 2nd book on any shelf, it takes 2 minutes to check.
For all other books, it takes 1 minute to check.
Special Rule: After finishing each shelf, the librarian takes a 3-minute break before moving to the next one.
Question: How many total minutes does the librarian spend on this routine, including the check times and breaks?
21 total minutes
Scenario: A library calculates fines based on the type of book and how many days it is overdue.
If the book is a "New Release":
Fines are $2 per day.
Else if it has been overdue for more than 10 days, the fine becomes a flat $30 replacement fee regardless of the daily rate.
If the book is "Standard Collection":
Fines are $0.50 per day.
Else if the member is a "Student," the fine is waived (0$) unless the book is more than 30 days late.
Question: A Student returns a "Standard Collection" book that is 14 days late, and a "New Release" that is 12 days late. What is the total fine they must pay?
$30.00
The Idea: An office building wants to make its elevator more efficient. They program it to stay on the floor where it was last used to save energy.
Logic: 1. When a button is pressed on any floor, the elevator moves to that floor and opens its doors. 2. If a person gets inside and presses a floor number, the elevator goes to that destination. 3. Else (if no button inside is pressed within 30 seconds), the elevator assumes the person changed their mind and it stays put with the doors closed.
The Problem: On Monday morning, a person on the 1st floor presses the button to go up. The elevator is already on the 1st floor. It opens its doors, the person steps in, and they press "Level 10." The elevator does nothing and eventually closes its doors, trapping the person on the 1st floor. What is the logical "dead end" here?
Missing Trigger
Concept: Iteration and Termination Conditions Iteration (or a Loop) is the process of repeating a set of instructions. To prevent a system from crashing or running forever (an Infinite Loop), it must have a Termination Condition—a specific moment where the "If" statement tells the loop to stop.
Question: Imagine a robot programmed to paint a fence.
The Instruction: "Paint one wooden slat, then move to the next slat. Repeat this as long as the slat is NOT painted."
The Situation: The robot paints a slat, but the paint is invisible to its sensors, so the sensor always reports the slat as "NOT painted."
Using the terms Iteration and Termination Condition, explain what happens to the robot and why this is a logical failure.
An Infinite Loop occurs.