BrightPath
Back to Course
Year 8 Coding & Computational Thinking Maths Link

Computational Problem Solving

Learn the four pillars of computational thinking and apply them to solve real problems with code!

The Four Pillars of Computational Thinking

Computational thinking is a way of approaching problems that makes them easier to solve -- with or without a computer. It has four key parts:

1

Decomposition

Breaking a big problem into smaller, manageable parts. Like building LEGO -- you don't try to build the whole thing at once.

Example: "Build a calculator" becomes: get input, identify operation, perform calculation, display result.
2

Pattern Recognition

Finding similarities or patterns among problems. If you've solved something similar before, you can reuse that solution.

Example: Adding items to a shopping cart is the same pattern as adding books to a library list.
3

Abstraction

Focusing on what's important and ignoring unnecessary details. A map is an abstraction of a city -- it shows roads but not every tree.

Example: A calculator doesn't need to know your name -- it only needs numbers and an operation.
4

Algorithm Design

Creating a step-by-step solution that can be followed to solve the problem every time.

Example: Writing the actual code: get two numbers, add them, display result.

Challenge 1: FizzBuzz

FizzBuzz is a classic programming challenge. The rules: count from 1 to a number, but replace multiples of 3 with "Fizz", multiples of 5 with "Buzz", and multiples of both with "FizzBuzz".

Decomposition

Part 1: Loop from 1 to n
Part 2: Check if divisible by 3 AND 5
Part 3: Check if divisible by 3 only
Part 4: Check if divisible by 5 only
function fizzBuzz(n) {
    let results = [];
    for (let i = 1; i <= n; i++) {
        if (i % 3 === 0 && i % 5 === 0) {
            results.push("FizzBuzz");
        } else if (i % 3 === 0) {
            results.push("Fizz");
        } else if (i % 5 === 0) {
            results.push("Buzz");
        } else {
            results.push(i);
        }
    }
    return results;
}

Challenge 2: Temperature Converter

Convert between Celsius and Fahrenheit using the formulas from Maths:

F = (C x 9/5) + 32     |     C = (F - 32) x 5/9

function celsiusToFahrenheit(celsius) {
    return (celsius * 9 / 5) + 32;
}

function fahrenheitToCelsius(fahrenheit) {
    return (fahrenheit - 32) * 5 / 9;
}

Challenge 3: Simple Calculator

Build a calculator using decomposition: separate the problem into getting inputs, identifying the operation, and performing the calculation.

function calculate(num1, operator, num2) {
    if (operator === "+") return num1 + num2;
    if (operator === "-") return num1 - num2;
    if (operator === "*") return num1 * num2;
    if (operator === "/") {
        if (num2 === 0) return "Error: division by zero!";
        return num1 / num2;
    }
    return "Unknown operator";
}

Key Vocabulary

Decomposition

Breaking a complex problem into smaller, more manageable sub-problems.

Pattern Recognition

Identifying similarities between problems to reuse existing solutions.

Abstraction

Focusing on the essential details and removing unnecessary complexity.

Algorithm Design

Creating a step-by-step solution that can be implemented in code.

Modulo (%)

The remainder after division. 7 % 3 = 1 because 7 / 3 = 2 remainder 1.

Edge Case

An unusual input that might cause problems. E.g., dividing by zero.

Worked Examples

1

Decompose: "Make a program that checks if a password is strong"

Sub-problems:

  1. Check if it's at least 8 characters long
  2. Check if it contains a number
  3. Check if it contains an uppercase letter
  4. Combine checks and give feedback

Each sub-problem can be solved independently, then combined. That's decomposition!

2

Trace through FizzBuzz for numbers 13, 14, 15

13: 13 % 3 = 1 (not 0), 13 % 5 = 3 (not 0). Output: 13

14: 14 % 3 = 2 (not 0), 14 % 5 = 4 (not 0). Output: 14

15: 15 % 3 = 0 AND 15 % 5 = 0. Both conditions true! Output: "FizzBuzz"

3

Why does the calculator check for division by zero?

Answer: Division by zero is undefined in mathematics -- it has no answer.

In code, dividing by zero can cause errors or return Infinity.

A good programmer thinks about edge cases -- unusual inputs that might cause problems -- and handles them with an if statement. This is an example of abstraction: understanding which details matter.

Knowledge Check

Select the correct answer for each question.

Question 1

What is "decomposition" in computational thinking?

Question 2

What does FizzBuzz output for the number 9?

Question 3

What is 100 degrees Celsius in Fahrenheit? (F = C x 9/5 + 32)

Question 4

What is an "edge case"?

Question 5

What is 15 % 4 (15 modulo 4)?

Key Concepts Summary

Year 7: Functions Year 8: Simulation