← Back to archive

Stdle #149 · iteration · 2026-11-02

What does this Go snippet output?

A past puzzle — fully playable. 4 attempts, hints on wrong guesses.

package main
import "fmt"
func main() {
a := counterMaker()
b := counterMaker()
fmt.Println(a(), a(), b())
}
func counterMaker() func() int {
n := 0
return func() int { n++; return n }
}
Iteration
4 attempts left

Answer & explanation