Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FizzBuzz across multiple languages
// A concurrent prime sieve
package main
import "fmt"
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
}
// The prime sieve: Daisy-chain Filter processes.
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch) // Launch Generate goroutine.
for i := 1; i <= 100; i++ {
if ( i % 3 == 0 && i % 5 == 0 ) {
fmt.Println("FizzBuzz")
} else if ( i % 3 == 0 ) {
fmt.Println("Fizz")
} else if ( i % 5 == 0 ) {
fmt.Println("Buzz")
} else {
fmt.Println(i)
}
ch1 := make(chan int)
ch = ch1
}
}
stuff = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
for i of stuff
if i % 5 == 0 && i % 3 == 0
console.log 'FizzBuzz'
elseif i % 3
console.log 'Fizz'
elseif i % 5
console.log 'Buzz'
else
console.log i
100.times do |index|
i = index + 1
if i % 3 === 0 && i % 5 === 0
puts 'FizzBuzz'
elsif i % 3 === 0
puts 'Fizz'
elsif i % 5 === 0
puts 'Buzz'
else
puts i
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment