FizzBuzz Problem
the famous FizzBuzz Problem.
this is my solution, it takes 5 min (if(!0) doesn’t work, so i have to use ==0, it takes about 3min), and i revise it in another 3 min to remove a temporary variable, and make code neat.
#!/usr/bin/perl
for $i (1..100) {
print $i if $i%3&&$i%5;
print "Fizz" if $i%3==0;
print "Buzz" if $i%5==0;
print "\n";
}
of course i can solve by using many other language.. but the basic is the same.. someone might save some character, but i don’t want to ruin the readablity nor main concept of algorithm.
http://tickletux.wordpress.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/
P.S. i can remove two mod operations by using a temp varibale, but i can’t say it’s right or wrong..
P.P.S. i found more simple solution from internet.. this code is just what i imagine.. cool..
print(($_%3?"":Fizz).($_%5?"":Buzz)or$_) for(1..100)
