Skip to content

Instantly share code, notes, and snippets.

@base10
Created January 18, 2010 00:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save base10/279674 to your computer and use it in GitHub Desktop.
Save base10/279674 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
function bottle (&$i) {
$bottle;
switch ($i) {
case ($i == 1):
$bottle = 'bottle';
break;
default:
$bottle = 'bottles';
}
return $bottle;
}
$i = 99;
while ($i > 0) {
echo "$i " . bottle($i) . " of beer on the wall, $i " . bottle($i) . " of beer\n";
$i--;
echo "take one down, pass it around, $i " . bottle($i) . " of beer on the wall\n";
}
?>
#!/usr/bin/perl
use strict;
use warnings;
use feature ':5.10';
my $i = 99;
while ($i > 0) {
say "$i " . bottles($i) . " of beer on the wall, $i " . bottles($i) . " of beer.";
$i--;
say "take one down, pass it around, $i " . bottles($i) . " of beer on the wall.";
}
sub bottles {
my $i = shift;
my $bottle;
given ( $i ) {
when ($i == 1) {$bottle = 'bottle';}
default {$bottle = 'bottles';}
}
return $bottle;
}
#!/usr/bin/python
def bottle(n): # Return bottle or bottles, appropriately
"""Return bottle or bottles, appropriately"""
bot = ''
if n == 1:
bot = 'bottle'
else:
bot = 'bottles'
return bot
i = 99
while i > 0:
print i, bottle(i), "of beer on the wall.", i, bottle(i), "of beer."
i = i - 1
print "take one down, pass it around,", i, bottle(i), "of beer on the wall"
#!/usr/bin/env ruby
def bottle(i)
bot = String.new
case i
when 1
bot = 'bottle'
else
bot = 'bottles'
end
bot
end
i = 99
while (i > 0)
puts "#{i.to_s} #{bottle(i)} of beer on the wall, #{i.to_s} #{bottle(i)} of beer."
i = i - 1
puts "Take one down, pass it around, #{i.to_s} #{bottle(i)} of beer on the wall."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment