A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-85.go
1packagemain
2
3import"fmt"
4
5typeKeystruct{
6Aint
7Bstring
8}
9
10funcmain(){
11m:=map[Key]int{}
12m[Key{1,"x"}]=7
13fmt.Println(m[Key{1,"x"}])
14}
Classes
Answer & explanation
Console output
7
Why
Comparable structs can be used as map keys; lookups compare keys with ==. A freshly built Key{1, "x"} is field-by-field equal to the one used for insertion, so it hashes and compares to the same slot, returning the stored value 7. Struct value equality is what makes this work.