Exercism: Go version of the 'Raindrops' exercise.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
535 B

9 years ago
9 years ago
9 years ago
  1. package raindrops
  2. import "strconv"
  3. const testVersion = 2
  4. func Convert(i int) string {
  5. var s string
  6. switch {
  7. case i%3+i%5+i%7 == 0:
  8. s = "PlingPlangPlong"
  9. case i%3+i%5 == 0:
  10. s = "PlingPlang"
  11. case i%3+i%7 == 0:
  12. s = "PlingPlong"
  13. case i%3 == 0:
  14. s = "Pling"
  15. case i%5+i%7 == 0:
  16. s = "PlangPlong"
  17. case i%5 == 0:
  18. s = "Plang"
  19. case i%7 == 0:
  20. s = "Plong"
  21. default:
  22. s = strconv.Itoa(i)
  23. }
  24. return s
  25. }
  26. // Iteration 2 Benchmark
  27. // PASS
  28. // BenchmarkConvert-12 5000000 309 ns/op
  29. // ok exercism/go/raindrops 1.869s