Skip to content

Instantly share code, notes, and snippets.

@patrickcousins
Created January 25, 2018 15:17
Show Gist options
  • Save patrickcousins/e74a422f78d2916771f2c5918dce155f to your computer and use it in GitHub Desktop.
Save patrickcousins/e74a422f78d2916771f2c5918dce155f to your computer and use it in GitHub Desktop.
bottles!
<?php
class Bottles {
function verse($num_bottles):string {
if ($num_bottles == 2) {
return "2 bottles of beer on the wall, 2 bottles of beer.\nTake one down and pass it around, 1 bottle of beer on the wall.";
}
if ($num_bottles == 1) {
return "1 bottle of beer on the wall, 1 bottle of beer.\nTake it down and pass it around, no more bottles of beer on the wall.";
}
if ($num_bottles == 0) {
return "No more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall.";
}
$minus_one = $num_bottles - 1;
return "$num_bottles bottles of beer on the wall, $num_bottles bottles of beer.\nTake one down and pass it around, $minus_one bottles of beer on the wall.";
}
function verses($start, $end) {
$verse_string = "";
for ($i = $start; $i >= $end; $i--) {
$verse_string = $verse_string . $this->verse($i);
if ($i != $end) {
$verse_string = $verse_string . "\n\n";
}
}
return $verse_string;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment