GCD in Go
Euclid's algorithm, still the shortest correct answer after two thousand years.
func gcd(a, b int) int {
for b != 0 {
a, b = b, a%b
}
return a
}
Keywords and builtins used here
forfuncintreturn
The run, in numbers
- Lines
- 6
- Characters to type
- 64
- Tokens
- 28
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 19 seconds.
Step 4 of 6 in Functions, step 13 of 30 in Language basics.