Created
November 9, 2011 10:08
-
-
Save ksauzz/1351022 to your computer and use it in GitHub Desktop.
Fizz Buzz
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
lists:foreach(fun({N,X}) -> io:format("~p: ~p~n",[N,X]) end ,[if (X rem 3 == 0) or (X rem 5 == 0) -> {X,"Buzz"}; true -> {X,"Fizz"} end || X <- lists:seq(1,100)]). |
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
// fizzbuzz without if statement and % operator. | |
class FizzBuzz { | |
public static void main (String [] args) { | |
for(int i=1; i<100; i++){ test(i); } | |
} | |
private static void test(int num) { | |
System.out.println(num+":"+bark(isMultiple(num))); | |
} | |
private static String bark(boolean b) { | |
return b ? "Buzz" : "Fizz"; | |
} | |
private static boolean isMultiple(int num) { | |
return mod(num, 3) == 0 || mod(num, 5) == 0; | |
} | |
private static int mod(int num, int baseNum) { | |
return num < baseNum ? num : mod(num - baseNum, baseNum); | |
} | |
} |
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
import sys;[sys.stdout.write(str(i) + "\n") for i in map(lambda x: (x%3==0 or x%5==0) and (x,"Buzz") or (x,"Fizz") ,range(1,100))] |
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
100.times.map {|n| (n%3==0||n%5==0) ? "#{n}: Fizz" : "#{n}: Buzz" }.each {|s|puts s} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment