Skip to main content
3 of 7
deleted 3 characters in body
LukStorms
  • 1.8k
  • 1
  • 12
  • 11

#Perl 5, 243 175 bytes

Many bytes were sacrificed to the void thanks to the inspirational URL from msh210. Which has a short solution from Andrew Savige that only needed few adaptations to meet the requirements of this challenge.

sub b{[@b=(abs||99,bottle.'s'x!!++$_,of,beer),on,the,wall]}say"@{+b}, @b.\n".($_?"Take one down and pass it around":"Go to the store and buy some more").", @{+b}.\n"for-99..-1

Original version that used a more straighforward method :

$}=" bottle";$s='s';$o=" of beer";$w=" on the wall";$i=99;while($i>1){say"$i$}$s$o$w, $i$}$s$o.";$s=''if--$i<2;say"Take one down and pass it around, $i$}$s$o$w.\n"}say"$i$}$s$o$w, $i$}$s$o.";say"Go to the store and buy some more, 99$}s$s$o$w."

Both are using the free -M5.010 switch for "say" instead of "print".

Cheers.

LukStorms
  • 1.8k
  • 1
  • 12
  • 11