Advertisement
Guest User

Untitled

a guest
Sep 10th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.83 KB | None | 0 0
  1. package raindrops
  2.  
  3. import "strconv"
  4.  
  5. func Convert(number int) string {
  6.  
  7.     // If the number is less than 3 then just return the number
  8.     // if number < 3 {
  9.     //  return strconv.Itoa(number)
  10.     // }
  11.  
  12.     three := "Pling"
  13.     five := "Plang"
  14.     seven := "Plong"
  15.     answer := ""
  16.  
  17.     for i := 3; i <= 8; i++ {
  18.         // Check if there is no remainder after division; therefore divisible
  19.         if number%i == 0 {
  20.             // If the divisible number is 3
  21.             if i == 3 {
  22.                 answer += three
  23.             }
  24.             // If the divisible number is 5
  25.             if i == 5 {
  26.                 answer += five
  27.             }
  28.             // If the divisible number is 7
  29.             if i == 7 {
  30.                 answer += seven
  31.             }
  32.         }
  33.     }
  34.     // The requirements are to only check for numbers up to 7
  35.     // so we can stop checking and just return what we have found
  36.     if answer == "" {
  37.         answer += strconv.Itoa(number)
  38.     }
  39.  
  40.     return answer
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement