Lesson 5 of 5
Puzzle Masterclass
Combine all four pillars of computational thinking to conquer intricate logic puzzles and riddles.
Learn it
You have now explored the four superpowers of computational thinking: Decomposition, Pattern Recognition, Abstraction, and Algorithm Design!
When you combine all four, you can solve almost any brain-teaser, logic riddle, or programming challenge that comes your way.
In this masterclass, we will tackle complex puzzles by breaking them apart, finding hidden clues, ignoring distractions, and writing step-by-step solutions.
Key terms
- Computational Thinking
- A problem-solving methodology encompassing decomposition, pattern recognition, abstraction, and algorithm design.
- State Space
- The set of all possible configurations or valid situations a puzzle or system can be in.
- Recursion
- A problem-solving method where a solution depends on solutions to smaller instances of the exact same problem.
- Deterministic
- A process that always produces the exact same output when given the same starting state and inputs.
Conquering the Wolf, Goat, and Cabbage Puzzle
Apply all four computational thinking pillars to transport a wolf, goat, and cabbage across a river safely.
- 11. Decompose the Rules: Identify independent constraints: wolf eats goat if left alone; goat eats cabbage if left alone; boat holds only farmer and one item.
- 22. Abstract the Environment: Ignore the river depth, cabbage color, and boat wood type. Model only which bank (Left or Right) each entity occupies.
- 33. Recognise the State Pattern: Notice that the goat is the common threat in both hazard pairs, so the goat must be moved first and managed carefully.
- 44. Design the Algorithm: Execute: Take goat across; return alone; take wolf across; return with goat; take cabbage across; return alone; take goat across.
Solving the River Crossing with Logic Checks
pythondef is_safe(state):
farmer, wolf, goat, cabbage = state
# If goat is with cabbage without farmer -> unsafe
if goat == cabbage and farmer != goat:
return False
# If wolf is with goat without farmer -> unsafe
if wolf == goat and farmer != wolf:
return False
return True
# State represents bank locations: 0 for West, 1 for East
initial_state = (0, 0, 0, 0) # All on West bank
print("Initial safe:", is_safe(initial_state))
# Bad move: farmer leaves wolf and goat alone
unsafe_move = (1, 0, 0, 0)
print("Unsafe move detected:", is_safe(unsafe_move))This Python function abstracts the puzzle state into simple numbers and evaluates safety rules mathematically.
Try it
Carefully trace this recursive puzzle algorithm. What value does puzzle_solve(3) return?
pythondef puzzle_solve(n):
if n <= 1:
return 1
return n + puzzle_solve(n - 1)
result = puzzle_solve(3)
print(result)Challenge
Apply computational thinking to solve the Tower of Hanoi puzzle with 3 disks across 3 pegs (A, B, C). Write down the exact move sequence to transfer all disks from Peg A to Peg C.
Pick whichever way suits you — every mode earns the same bonus XP.
Write at least 40 more characters to submit.
Mark your own work
Guided walkthrough — 0/5 clues revealed
- Clue 1 locked — reveal it only if you get stuck.
- Clue 2 locked — reveal it only if you get stuck.
- Clue 3 locked — reveal it only if you get stuck.
- Clue 4 locked — reveal it only if you get stuck.
- Clue 5 locked — reveal it only if you get stuck.
Each clue costs 5 XP (never below 25 XP). You'd earn 50 XP right now.
Extension: Write a recursive Python function hanoi(n, source, target, auxiliary) that prints each move step automatically for any number of disks n.