Playing Fizz Buzz

A very typical test of programming skills is doing a short one-liner for something that is not easily a one-liner.

Today I did the FizzBuzz test. The task is simple; For a range of numbers 1..100 print “Fizz” if the number is divisible by 3 and “Buzz” if the number is divisible by 5, otherwise just print the number.

Python is my weapon of choice.

print(*map(lambda n:"Fizz"*(n%3==0)+"Buzz"*(n%5==0) or n, range(1,101)))

Don’t do this for production code 🙄

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s