fork download
  1. package main
  2.  
  3. import (
  4. "errors"
  5. "fmt"
  6. )
  7.  
  8. func tekaTekiTeko(batas uint) ([]string, error) {
  9. if batas < 20 {
  10. return nil, errors.New("Eror! Batas minimal adalah 20")
  11. }
  12.  
  13. output := make([]string, 0, batas)
  14.  
  15. for i := uint(1); i <= batas; i++ {
  16. result := ""
  17.  
  18. if i%2 == 0 {
  19. result += "Teka"
  20. }
  21. if i%3 == 0 {
  22. result += "Teki"
  23. }
  24. if i%5 == 0 {
  25. result += "Teko"
  26. }
  27.  
  28. if result == "" {
  29. result = fmt.Sprint(i)
  30. }
  31.  
  32. output = append(output, result)
  33. }
  34.  
  35. return output, nil
  36. }
  37.  
  38. func main() {
  39. hasil, err := tekaTekiTeko(30)
  40. if err != nil {
  41. fmt.Println(err)
  42. return
  43. }
  44.  
  45. for _, v := range hasil {
  46. fmt.Println(v)
  47. }
  48. }
  49.  
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
1
Teka
Teki
Teka
Teko
TekaTeki
7
Teka
Teki
TekaTeko
11
TekaTeki
13
Teka
TekiTeko
Teka
17
TekaTeki
19
TekaTeko
Teki
Teka
23
TekaTeki
Teko
Teka
Teki
Teka
29
TekaTekiTeko