123456789101112131415161718192021222324252627282930 |
- package kata
- import "fmt"
- func Zombie_shootout(zombies, initial_range, ammo int) string {
- remaining := func(time int) int {
- return zombies - time
- }
- distance := func(time int) int {
- if initial_range <= time / 2 {
- return 0
- }
- return initial_range - time / 2
- }
- time := 0
- for {
- currentAmmo := ammo - time
- if remaining(time) == 0 {
- return fmt.Sprintf("You shot all %d zombies.", zombies)
- }
- if distance(time) == 0 {
- return fmt.Sprintf("You shot %d zombies before being eaten: overwhelmed.", time)
- }
- if currentAmmo == 0 {
- return fmt.Sprintf("You shot %d zombies before being eaten: ran out of ammo.", time)
- }
- time++
- }
- }
|