Fizz Buzz: Can You Do It?
Fizz Buzz. Never been asked it and I'm glad because if I were I would honestly have to laugh because it is such a simple problem write a program for...
The Fizz Buzz "challenge" is:
Write a program that prints numbers from 1 to 100 except if that number is a 3 or a 5. If the number is a multiple of 3 print "Fizz" and if the number is a multiple of 5 then print "Buzz". If the number is a multiple of both then print "FizzBuzz". Go!
Easy enough, right? Any developer worth their salt should see the code in their head as they hear or read the problem. It should click almost instantly.
I am surprised to read that people cannot do Fizz Buzz in an interview[1][2][3]. As a test to myself I just wrote Fizz Buzz in SQL, which I don't know very much SQL and I used Google a lot, but I was still able to produce a SQL version (code at the end of this post) of Fizz Buzz that puts the variables in a table in about 15 minutes. Given a language I know well... I could write it in under 5 minutes easy.
As the article mentions, these people have degrees in Computer Science, call themselves senior developers, etc. Yet they cannot write a simple Fizz Buzz solution.
Hearing stories from Katie about her high school students and their complete disregard of their education leads me to think this is a societal problem. Students don't even learn in the classroom anymore and they tune out their education almost entirely, so those who make it to college, study just for their classes. Extracurricular education is almost non-existent it seems.
Maybe it's because I have a passion for software development, but I could not wait to get off for summer in school so that I could learn a new language or read a design patterns book. Sometimes, if I didn't feel like dealing with books, I would do something having to do with software development like writing code or learning an important technology like source control or continuous integration.
I understand that in some cases there isn't time during the semester and students need money and the only time to earn it is in those off hours from education, so I would propose looking for internships in the field of study. Most of the time they usually pay well and you learn a lot. With Google's Summer of Code you don't even have to leave home.
In order for us to continue to innovate, we need to keep learning. We need to learn something new even if it isn't an assignment or homework. Consuming TV, pointless internet news, and other trash all the time could be the downfall of our society, if not at least the downfall of our own minds.
As promised, Fizz Buzz in SQL:
1 DECLARE @counter INT
2 DECLARE @outputtable TABLE
3 (
4 outpt VARCHAR(8)
5 )
6 SET @counter = 0
7 WHILE @counter < 100
8 BEGIN
9 SET @counter = @counter + 1
10 IF @counter % 3 = 0 AND @counter % 5 = 0
11 INSERT INTO @outputtable (outpt) VALUES ('FizzBuzz')
12 ELSE IF @counter % 3 = 0
13 INSERT INTO @outputtable (outpt) VALUES ('Fizz')
14 ELSE IF @counter % 5 = 0
15 INSERT INTO @outputtable (outpt) VALUES ('Buzz')
16 ELSE
17 INSERT INTO @outputtable (outpt) VALUES (CAST(@counter AS VARCHAR))
18 END
19 SELECT * FROM @outputtable