Loyalty points for a basket
The card scheme awards one point for every full ten lira spent, and doubles that on promotion days.
- The amount arrives in kuruş, so ten lira is 1000.
- Part of a ten does not earn anything.
- A negative amount is a refund and earns nothing.
pointsFor(spend: int, doubleDay: bool) → int
Go needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
func pointsFor(spend int, doubleDay bool) int {
}
Worked examples
| Call | Result |
|---|---|
pointsFor(10000, false) | 10 |
pointsFor(10999, false) | 10 |
pointsFor(10000, true) | 20 |
pointsFor(999, false) | 0 |
Hint
Integer-divide by 1000, then double if the flag is set.
Reference solution in Go
func pointsFor(spend int, doubleDay bool) int {
if spend <= 0 {
return 0
}
base := spend / 1000
if doubleDay {
return base * 2
}
return base
}