I can code that FizzBuzz function with only two tests
boston.conman.org
I can code that FizzBuzz function with only two tests
1–4 of 4 posts
Re: I can code that FizzBuzz function with only two tests
#2Or with AWK:
echo 15 | awk '$1%3==0{s=s"Fizz"} $1%5==0{s=s"Buzz"} END{print s}'
Re: I can code that FizzBuzz function with only two tests
#3Or with AWK: echo 15 | awk '$1%3==0{s=s"Fizz"} $1%5==0{s=s"Buzz"} END{print s}'
Not that it affects your overall point, but you probably want:
awk '$1%3==0{s=s"Fizz"} $1%5==0{s=s"Buzz"} {print s;s=""}'
Otherwise, consider: % printf "3\n5\n9\n15\n16\n" | awk '$1%3==0{s=s"Fizz"} $1%5==0{s=s"Buzz"} END{print s}'
FizzBuzzFizzFizzBuzz
For bonus points, the following won't treat non-numerics as FizzBuzz: awk '$1+0\!=$1 {print"";next} $1%3==0{s=s"Fizz"} $1%5==0{s=s"Buzz"} {print s;s=""}'Re: I can code that FizzBuzz function with only two tests
#4There is no clever way to compute FizzBuzz. It is a constant.