Created
May 14, 2012 17:29
-
-
Save foota/2695210 to your computer and use it in GitHub Desktop.
FizzBuzz
This file contains 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
#include <iostream> | |
template<int N, int M3, int M5> struct FB | |
{ FB() { std::cout << N << std::endl; } }; | |
template<int N, int M5> struct FB<N, 0, M5> | |
{ FB() { std::cout << "Fizz" << std::endl; } }; | |
template<int N, int M3> struct FB<N, M3, 0> | |
{ FB() { std::cout << "Buzz" << std::endl; } }; | |
template<int N> struct FB<N, 0, 0> | |
{ FB() { std::cout << "FizzBuzz" << std::endl; } }; | |
template<int N> struct FizzBuzz | |
{ FizzBuzz() { FizzBuzz<N-1>(); FB<N, N%3, N%5>(); } }; | |
template<> struct FizzBuzz<0> {}; | |
int main() { FizzBuzz<100>(); return 0; } |
This file contains 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
-module(fizzbuzz). | |
-export([fb/1]). | |
fb(0) -> ok; | |
fb(N) -> | |
fb(N - 1), | |
if | |
N rem 15 =:= 0 -> io:put_chars("FizzBuzz"); | |
N rem 3 =:= 0 -> io:put_chars("Fizz"); | |
N rem 5 =:= 0 -> io:put_chars("Buzz"); | |
true -> io:write(N) | |
end, | |
io:nl(). |
This file contains 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
#include <iostream> | |
template<int N, int M3=N%3, int M5=N%5> struct FB | |
{ FB() { FB<N-1, (N-1)%3, (N-1)%5>(); std::cout << N << std::endl; } }; | |
template<int N, int M5> struct FB<N, 0, M5> | |
{ FB() { FB<N-1, (N-1)%3, (N-1)%5>(); std::cout << "Fizz" << std::endl; } }; | |
template<int N, int M3> struct FB<N, M3, 0> | |
{ FB() { FB<N-1, (N-1)%3, (N-1)%5>(); std::cout << "Buzz" << std::endl; } }; | |
template<int N> struct FB<N, 0, 0> | |
{ FB() { FB<N-1, (N-1)%3, (N-1)%5>(); std::cout << "FizzBuzz" << std::endl; } }; | |
template<> struct FB<0, 0, 0> {}; | |
int main() { FB<100>(); return 0; } |
This file contains 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
-module(fizzbuzz). | |
-export([fb/3, fizzbuzz/1]). | |
fb(_, 0, 0) -> io:put_chars("FizzBuzz\n"); | |
fb(_, 0, _) -> io:put_chars("Fizz\n"); | |
fb(_, _, 0) -> io:put_chars("Buzz\n"); | |
fb(N, _, _) -> io:write(N), io:nl(). | |
fizzbuzz(0) -> ok; | |
fizzbuzz(N) -> fizzbuzz(N - 1), fb(N, N rem 3, N rem 5). |
This file contains 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
-module(fizzbuzz). | |
-export([fb/1]). | |
fb(0, 0, 0) -> ok; | |
fb(N, 0, 0) -> fb(N-1, (N-1) rem 3, (N-1) rem 5), io:put_chars("FizzBuzz\n"); | |
fb(N, 0, _) -> fb(N-1, (N-1) rem 3, (N-1) rem 5), io:put_chars("Fizz\n"); | |
fb(N, _, 0) -> fb(N-1, (N-1) rem 3, (N-1) rem 5), io:put_chars("Buzz\n"); | |
fb(N, _, _) -> fb(N-1, (N-1) rem 3, (N-1) rem 5), io:write(N), io:nl(). | |
fb(N) -> fb(N, N rem 3, N rem 5). |
This file contains 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
exec(r"""%s'''gzga*%%%%,hmkl*ocr*nco`fc"a8ajp*mpf*a+\\0+.p%%%s'kormpv"mq.`cqg469gzga*`cqg46,fgamfgqvpkle*mq,rcvj,`cqglcog*]]dkng]]+Y8/1_++')))%%+++''')))"""%(lambda _:(_,_))("exec(''.join(map(lambda _:chr(ord(_)^2),")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://handasse.blogspot.com/2009/03/erlangfizzbuzzc.html
http://handasse.blogspot.com/2011/08/blog-post.html