Last active
August 29, 2015 14:12
-
-
Save jonbodner/a2d103039f024432f627 to your computer and use it in GitHub Desktop.
FizzBuzz for Go with no conditionals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type fber func(int)string | |
func fizzer(i int) string { | |
return "fizz" | |
} | |
func buzzer(i int) string { | |
return "buzz" | |
} | |
func fizzbuzzer(i int) string { | |
return fizzer(i)+buzzer(i) | |
} | |
func num(i int) string { | |
return fmt.Sprintf("%d",i) | |
} | |
func ranger(i int) []struct{} { | |
return make([]struct{},i) | |
} | |
func fizzBuzz() { | |
m := []fber{ | |
num, | |
num, | |
fizzer, | |
num, | |
buzzer, | |
fizzer, | |
num, | |
num, | |
fizzer, | |
buzzer, | |
num, | |
fizzer, | |
num, | |
num, | |
fizzbuzzer, | |
} | |
for i, _ := range(ranger(100)) { | |
v := m[(i)%15] | |
fmt.Println(v(i+1)) | |
} | |
} | |
func main() { | |
fizzBuzz() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to remove the for condition and change it to a for/range loop.