Theory
What an algorithm is
A computer does not understand "roughly". An algorithm is a finite, unambiguous sequence of steps that turns input into a result. Two words matter most:
- Finite — the steps end at some point. "Repeat until it works" with no stopping rule is not an algorithm.
- Unambiguous — every step can be done in exactly one way. "Take the bigger number" is clear; "take the nicer number" is not.
Before writing code, it helps to write the algorithm as pseudocode — plain sentences, no programming language at all. Here is "find the largest number in a list":
1. Take the FIRST number of the list and call it "biggest".
2. Walk through the remaining numbers one by one.
3. If a number is bigger than "biggest" — replace "biggest" with it.
4. When the numbers run out, "biggest" is the answer.
In step 3 of this lesson we will turn this exact algorithm into real Go code — you will see the code repeats the sentences almost word for word.
Tip. The whole course is one exercise: describe the steps in human language, then translate them into Go. If you can write the algorithm, you can already program — only the syntax is left.