The FizzBuzz Test

While reading Jeff Atwood’s blogpost entitled Why Can’t Programmers Program? I thought of testing whether I can pass the simple FizzBuzz test for programming he mentions. You can read the details of the test on his blogpost.

So I wrote a script in PHP, the language I am currently active in, to do what the test asks us to do.

But then, why stop at just solving the problem when you can optimize code for timepass?

I began with a 24 line-long (without counting empty lines) chunk of indented code, using a simple for loop and a bunch of if statements. But then I wanted to reduce the size of the code, so I decided to use the shorthand for if, and get rid of variable assignments that don’t “do” anything really. Now I am down to 5 lines of code, including the two lines of the for loop.

Turns out I am a programmer (though not formally educated as a programmer), and a good one at that – I passed the FizzBuzz Test!! :) Do I get a job as a programmer now? :P

Here is the output of the script (yes, the script ran when you loaded this page):

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

On Top Of The World: May 2012

On top of the world
On our way to Leh, July 2011.

Wallpapers:

This be Sarchu

This be Sarchu
The vast plateau-esque high-land where travellers sleep in tents.

And one can see millions of stars at night

April 2012: A Good Morning en route Ladakh

A Good Morning en route Ladakh
The night halt at Keylong was comfortable – the most comfortable we had until we reached Leh.

And the Himalayas greeted us thus after the comfortable sleep.

Devotion

Devotion
Devotees lighting candles for St. Gregorius Gevargis at St. Peter’s Church, Parumala, Kerala, December, 2011
on Flickron Facebook

Recaptured’s Magazine Interview

Bucket lists make for interesting reads. They give an insight into the character and personality of the person who wrote it.

A middle class Indian boy like yours truly who grew up on a staple diet of books and magazines more than cable television has a particular kind of bucket list. So far two items had been crossed off it: getting published and lighting the lamp at a government institution’s festival. The former was a happy moment, the latter an embarrassing one. But that’s a story for another time. It’s time to tell you about the third item that has been ticked off the list.

3. Interview in a major national magazine

Pool is one of India’s leading creative arts & design magazines. And owing to the fact that it has been started by Sudhir Sharma himself, it’s immensely popular in the professional design community.

They have been kind enough to feature my interview in the March 2012 issue. You can contact them for purchasing a copy, or simply read the issue online here – the interview appears on page 12 onwards in the print magazine, which corresponds to page 14 onwards online.

Please read, comment and share :)

Ready for Take-Off

Ready for Take-Off

Posted in: photography by hypnos No Comments , ,

Ankita

Ankita

on Flickron Facebook

Marching Ahead

Marching Ahead
on Flickron Facebook

Posted in: photography by hypnos No Comments , , ,

What are YOU looking at?

What are YOU looking at?

Switch to our mobile site