Programming
Problem solving, readable code, and the building blocks of software.
03Teaching
Two complementary paths: programming turns ideas into executable steps; mathematics develops the reasoning that makes those steps understandable.
Problem solving, readable code, and the building blocks of software.
Logical thinking, mathematical language, and structured problem solving.
Move from an explanation to a worked example, then independent practice.
∴LEARNING CORNER
A small example of how I like to teach: start with an executable idea, then reveal the structure behind it.
Start with an accumulator. Each iteration adds the current number to the running total.
def sum_to(n):
total = 0
for value in range(1, n + 1):
total += value
return total
sum_to(5) # 15For a nonnegative integer n, the loop performs n additions: O(n) time and O(1) auxiliary space.
Write the same sum forwards and backwards. Each column adds to n + 1, and there are n columns.
S = 1 + 2 + ⋯ + n
S = n + (n − 1) + ⋯ + 1
2S = n(n + 1)
S = n(n + 1) / 2The formula gives a direct calculation and explains why the solution works.
Find the sum of even numbers from 2 to 2n. Can you write both a loop and a direct formula?
2 + 4 + ⋯ + 2n = 2(1 + 2 + ⋯ + n) = n(n + 1).
sum(range(2, 2 * n + 1, 2))The two perspectives complement each other: code expresses the steps; mathematics reveals the structure.