k.go 658 B

123456789101112131415161718192021222324252627282930
  1. package kata
  2. import "fmt"
  3. func Zombie_shootout(zombies, initial_range, ammo int) string {
  4. remaining := func(time int) int {
  5. return zombies - time
  6. }
  7. distance := func(time int) int {
  8. if initial_range <= time / 2 {
  9. return 0
  10. }
  11. return initial_range - time / 2
  12. }
  13. time := 0
  14. for {
  15. currentAmmo := ammo - time
  16. if remaining(time) == 0 {
  17. return fmt.Sprintf("You shot all %d zombies.", zombies)
  18. }
  19. if distance(time) == 0 {
  20. return fmt.Sprintf("You shot %d zombies before being eaten: overwhelmed.", time)
  21. }
  22. if currentAmmo == 0 {
  23. return fmt.Sprintf("You shot %d zombies before being eaten: ran out of ammo.", time)
  24. }
  25. time++
  26. }
  27. }