Skip to content

Instantly share code, notes, and snippets.

@pmurias
Created October 14, 2018 18:19
Show Gist options
  • Save pmurias/b4b147048a70e333e61ec8c298096491 to your computer and use it in GitHub Desktop.
Save pmurias/b4b147048a70e333e61ec8c298096491 to your computer and use it in GitHub Desktop.
99 Bottles of Beer
for 99...1 -> $bottles {
sing $bottles, :wall;
sing $bottles;
say "Take one down, pass it around";
sing $bottles - 1, :wall;
say "";
}
#| Prints a verse about a certain number of beers, possibly on a wall.
sub sing(
Int $number, #= Number of bottles of beer.
Bool :$wall, #= Mention that the beers are on a wall?
) {
my $quantity = $number == 0 ?? "No more" !! $number;
my $plural = $number == 1 ?? "" !! "s";
my $location = $wall ?? " on the wall" !! "";
say "$quantity bottle$plural of beer$location"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment