4 ms·
A correct FizzBuzz in awk (the version in the article doesn't print numbers in the general case): $ seq 1 100 | awk '!($1%3){printf "Fizz";p=1}!($1%5){prin
by nonchalance 13y ago
A correct FizzBuzz in awk (the version in the article doesn't print numbers in the general case):
$ seq 1 100 | awk '!($1%3){printf "Fizz";p=1}!($1%5){printf "Buzz";p=1}!p{printf $1}{printf "\n";p=0}'
- billjings 13y agoArgh. I should know what FizzBuzz is before I write one. I've updated the implementation in my post to be... not wrong. (It's a little different from yours, though.)
- nonchalance 13y agoI hope it's shorter :) 60 chars: !($1%3){$2="Fizz"}!($1%5){$2=$2 "Buzz"}!$2{$2=$1}{print $2}
- billjings 13y agoNice. Using $2 as an auto-clearing global is a neat little hack!