Skip to content

Instantly share code, notes, and snippets.

@tnoda
Created February 21, 2015 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tnoda/17c0aaddf9c00adf79a4 to your computer and use it in GitHub Desktop.
Save tnoda/17c0aaddf9c00adf79a4 to your computer and use it in GitHub Desktop.
(let [N (read-line)
digits (map #(Character/digit % 10) N)
m3 (rem (apply + digits) 3)
m5 (rem (last digits) 5)
answer (cond
(and (zero? m3) (zero? m5)) "Fizz Buzz"
(zero? m3) "Fizz"
(zero? m5) "Buzz"
:else N)]
(println answer))
package main
import (
"fmt"
)
func main() {
var N string
fmt.Scan(&N)
var x, y int
for _, r := range N {
y = int(r - '0')
x += y
}
x %= 3
y %= 5
if x == 0 && y == 0 {
fmt.Println("Fizz Buzz")
return
}
if x == 0 {
fmt.Println("Fizz")
return
}
if y == 0 {
fmt.Println("Buzz")
return
}
fmt.Println(x, y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment