A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-38.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6counts:=map[string]int{}
7counts["go"]++
8counts["go"]++
9fmt.Println(counts["go"],counts["rust"])
10}
Maps
Answer & explanation
Console output
2 0
Why
counts["go"]++ reads the current value (the zero value 0 on the first call, since the key is absent) and stores value+1, giving 1 then 2. This zero-value-on-read behavior is exactly what makes maps convenient as counters without pre-initializing keys. "rust" is never written, so reading it yields 0.