A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-130.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6s:=[]int{1,2,3}
7s=append(s,4)
8fmt.Println(s,len(s),cap(s))
9}
Slices
Answer & explanation
Console output
[1 2 3 4] 4 6
Why
The literal gives cap 3 with no room to grow, so append allocates a new larger backing array and copies the elements. Go’s growth heuristic for small slices doubles capacity, so the new cap is 6 while len becomes 4.