A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-178.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6a:=[]int{1,2,3,4}
7b:=a[1:2:3]
8fmt.Println(len(b),cap(b))
9}
Slices
Answer & explanation
Console output
1 2
Why
The three-index form a[low:high:max] lets you cap the resulting slice’s capacity at max-low instead of running to the end of the array. Here len is 2-1 = 1 and cap is 3-1 = 2. This is used to limit how far a reslice or append can reach into the shared backing array.