Python, Ruby and Clojure

by Security Dude

Ruby

#!/usr/bin/env ruby

1.upto(100) do |i|
if i % 5 == 0 and i % 3 == 0
puts "FizzBuzz"
elsif i % 5 == 0
puts "Buzz"
elsif i % 3 == 0
puts "Fizz"
else
puts i
end
end

Python

#!/usr/bin/env python

for i in range(1,101):
if i % 5 == 0 and i % 3 == 0:
print "FizzBuzz"
elif i % 5 == 0:
print "Buzz"
elif i % 3 == 0:
print "Fizz"
else:
print i

Clojure

(doseq [i (range 1 101)]
(cond (and (multiple? i 3)(multiple? i 5))
(println "FizzBuzz")
(multiple? i 3)
(println "Fizz")
(multiple? i 5)
(println "Buzz")
:else (println i)))

Advertisements