3 ms·
for(1..100){$_%15==0?print"FizzBuzz":$_%5==0?print"Buzz":$_%3==0?print"Fizz":print} Is my best perl golf so far... wrote this one eons ago. The site doesn't se
by agentultra 14y ago
for(1..100){$_%15==0?print"FizzBuzz":$_%5==0?print"Buzz":$_%3==0?print"Fizz":print}
Is my best perl golf so far... wrote this one eons ago. The site doesn't seem to work well however and it won't let me submit it. Would obviously be shorter with "say" instead of "print."
- rvivek 14y agoThis is the expected output (http://cdn.hackerrank.com/fizzbuzz.txt http://cdn.hackerrank.com/fizzbuzz.txt)
- deleted 14y ago[deleted]
- colomon 14y agosay (1..100).map({ $_ %% (3|5) ?? ("Fizz" if $_ %% 3) ~ ("Buzz" if $_ %% 5) !! $_ }).join("\n") is my quick stab at a Perl 6 version. About the same length if I take out the spaces (which I'd rather not!).
- agentultra 14y agoPerl 6 is so cool! I like the bit $_ %% (3|5) A pretty nifty way to condense multiple values into a single test. I don't always perl, but when I do sometimes I like to golf because it's fun.
- rmah 14y agoprint(($_%3?"":Fizz).($_%5?"":Buzz)||$_,"\n")for 1..100 No need to quote the strings in some cases :-)