Skip to content

Instantly share code, notes, and snippets.

@jrmoran
Created December 18, 2011 10:16
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 jrmoran/1492951 to your computer and use it in GitHub Desktop.
Save jrmoran/1492951 to your computer and use it in GitHub Desktop.
fizzbuzz
(defn buzziffy [a b x]
(cond (and (zero? (mod x a)) (zero? (mod x b))) "FizzBuzz"
(zero? (mod x a)) "Fizz"
(zero? (mod x b)) "Buzz"
:else x))
(println (apply str (map #(str (buzziffy 3 5 %) "\n")
(range 1 100))))
buzziffy = (a, b, x)->
ret = ''
ret += 'Fizz' if x % a is 0
ret += 'Buzz' if x % b is 0
if ret is '' then x else ret
console.log buzziffy 3, 5, n for n in [0..100]
var buzziffy = function(a, b, x){
var ret = '';
if(x % a === 0) ret += 'Fizz';
if(x % b === 0) ret += 'Buzz';
return ret === '' ? x : ret;
};
for(var i = 0; i <= 100; i++){
console.log( buzziffy(3, 5, i) );
}
(1..100).each{ |n|
str = ''
str += 'Fizz' if(n % 3 == 0)
str += 'Buzz' if(n % 5 == 0)
puts str.empty? ? n : str
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment