How Would You Write a "99 Bottles of Beer" Program?
A while back, I posted about 99 Bottles of Beer In PHP in an effort to see how others might programmatically write code that would take an initial variable and then iterate it down until it reached a specific value and then return a message.
Many programming languages offer multiple ways of accomplishing the same task and I decided that a great learning experience for me and for others would be to ask everyone and anyone to contribute their own variations using any language.
I posted this on GITHub and would love for you to contribute to it as well.
My examples use PHP and Python, since those were the two languages I am most familiar with.
It would be really awesome if you would add your own ideas as well.
So, please feel free to add it it. Anything goes! If you have a different approach in PHP, do a pull request. If you know PERL, add yours! I would like to collect as many examples as possible.


Comments
Alexander Kreditkort (not verified)
Wed, 09/14/2011 - 13:36
Permalink
I looked up your code on the
I looked up your code on the GITHub link. There is a logic error on the 9th line. If it is "if($bottles > 1) {" then the line "Time to buy more beer!" will not be printed. You have to make it "if($bottles < 1) {".
Also I am curious why you write the BREAK tag as < /br >. The XHTML way I know is < br /> while HTML is < br >.
:D
admin
Thu, 09/15/2011 - 17:04
Permalink
Thanks for the comments and
while ($bottles > 0) {andwhile numofbottles >= 1:As far as the breaks, I really can't say why I did it! Please feel free to fork the repo and make your changes. I will merge them back.Alexander Kreditkort (not verified)
Fri, 09/23/2011 - 03:38
Permalink
I was referring to PHP. When
I was referring to PHP. When I ran the code it stopped at 1 without printing the "Time to buy more beer." :)
admin
Fri, 09/23/2011 - 05:21
Permalink
Yikes! You're right!
Yikes! You're right!
I've corrected it. Thanks for the tip.
Add new comment