A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-49.go
1packagemain
2
3import"fmt"
4
5funcmain(){
6a:=[]int{1,2,3,4,5}
7b:=a[1:3]
8c:=b[:4]
9fmt.Println(b,c)
10}
Slices
Answer & explanation
Console output
[2 3] [2 3 4 5]
Why
b := a[1:3] has length 2 but capacity 4, because capacity extends from the slice start to the end of the underlying array. Reslicing with b[:4] is allowed since 4 is within cap, revealing the elements past b’s length: [2 3 4 5]. You can grow a slice up to its capacity by reslicing.