package bookstore const bookPrice = 800 // cents type basket struct { books map[int]int // type:count } func newBasket(books []int) basket { b := basket{books: make(map[int]int)} for _, v := range books { b.books[v]++ } return b } // discount in percent func (b basket) discount() int { discounts := []int{0, 0, 5, 10, 20, 25} // percent return discounts[len(b.books)] } func (b basket) price() int { var price int for _, v := range b.books { price += v * (bookPrice - bookPrice*b.discount()/100) } return price } func Cost(books []int) int { return newBasket(books).price() }