Back to Challenge Set 7

Pseudocode Challenge: Logic

Difficulty  

divider

Objective

Four problems in AP exam notation, covering AND, OR, NOT, and RANDOM — Activities 1.15 and 1.16.

Work these on paper. There is no computer on exam day. Three are traces and one is a translation.


What You Are Allowed to Use

Everything from the exam reference sheet that we have covered so far. Nothing else appears in these problems.

Assignment
a ← expression
Display
DISPLAY(expression)
Boolean operators
NOT a
a AND b
a OR b
Random
RANDOM(a, b)
Comparison
a = b a ≠ b
a > b a < b
a ≥ b a ≤ b
Selection
IF(condition)
{
...
}
ELSE
{
...
}

Three rules that catch people:

  • RANDOM(a, b) includes both ends. RANDOM(1, 6) can give a 1 and it can give a 6 — which is not how Random.Shared.Next counts, and Problem 4 is about exactly that.
  • The operators are words: NOT, AND, OR. They mean what the symbols mean, and they apply in that order — the same order C# uses.
  • There is no ELSE IF. A chain is built by putting a whole new IF inside an ELSE block.

Worked Example

The same decision, written both ways.

C#
int day = 6;
bool onDuty = false;
if (day >= 6 && !onDuty)
{
Console.WriteLine("Rest");
}
Exam Notation
day ← 6
onDuty ← false
IF(day ≥ 6 AND NOT onDuty)
{
DISPLAY("Rest")
}

&& becomes AND, ! becomes NOT, and the ! that was jammed against its variable becomes a word with a space after it. That is why the exam notation is easier to read aloud — and why a ! is so easy to miss going the other way.


The Problems

1 — Trace

What does this display?

Problem 1
age ← 16
hasPass ← false
IF(age ≥ 18 OR hasPass)
{
DISPLAY("Enter")
}
ELSE
{
DISPLAY("Denied")
}

2 — Trace

What does this display, and in what order?

Problem 2
x ← 12
y ← 5
IF(NOT (x < y))
{
DISPLAY("first")
}
IF(x > 10 AND y > 10)
{
DISPLAY("second")
}
IF(x > 10 OR y > 10)
{
DISPLAY("third")
}

Careful: these are three separate IF statements, not a chain. More than one of them can run. Activity 1.13 made this distinction and it is still the most common way to lose a point here.


3 — Trace

This program is run many times. List every value it could possibly display.

Problem 3
n ← RANDOM(1, 4)
DISPLAY(n * 2)

There are four of them, and getting three means you dropped an end off the range.


4 — Translate

Rewrite this C# in exam notation. One of the numbers has to change, and it is the whole point of the problem.

Problem 4
int roll = Random.Shared.Next(1, 7);
if (roll == 6)
{
Console.WriteLine("Six!");
}
else
{
Console.WriteLine("Not six.");
}

Both versions must roll the same six faces. Write one sentence saying which number you changed and why.


Submit

  • What problems 1 and 2 display, in order
  • Every value problem 3 could display
  • Your exam-notation translation of problem 4, plus the sentence about the number you changed
  • One sentence: which problem took you longest, and what slowed you down?

This is graded on completion, not accuracy.

Commence Challenge