- or download this
x = "012345"
s = x[0:3] # s contains "012"
...
s = x[::-2] # same thing (using default)
s = x[::-1] # s contains "543210" (i.e. string reverse)
s = x[::0] # "ValueError: slice step cannot be zero"
- or download this
n=99
z=lambda:`n or 99`+" bottle"+"s of beer on the wall"[n==1:]
while n:y=z();n-=1;print"%s, %s.\n"*2%(y,y[:-12],n and"Take one down a
+nd pass it around"or"Go to the store and buy some more",z())
- or download this
n and"Take one down and pass it around"or"Go to the store and buy some
+ more"
- or download this
"Take"if n else"Go to"
(n>0)*"Take"or"Go to"
...
("Go to","Take")[n>0]
n and"Take"or"Go to"
"GToa kteo"[n>0::2] # "Slice and Dice" wins this golf!
- or download this
99 bottles of beer on the wall,<space>
99 bottles of beer.\nTake one down and pass it around,<space>
98 bottles of beer on the wall.\n\n
- or download this
i=298
while~-i:print i/3or 99,'bottle'+'s of beer on the wall.\n\n'[2<i<6:9+
+i%3*12]+'..\n\nGToa kteo otnhee dsotwonr ea nadn dp absusy isto ma
+er omuonrde,,'[(i>3)+i%3*68::2],;i-=1
- or download this
'..\n\nGToa kteo otnhee dsotwonr ea nadn dp absusy isto maer omuonr
+de,,'[(i>3)+i%3*68::2]
- or download this
i=298
while~-i:print i/3or 99,'bottle'+'s of beer on the wall'[2<i<6:9+i%3*1
+4]+('.\n'+'GToa kteo otnhee dsotwonr ea nadn dp absusy isto maer o
+muonrde,,'[i>3::2],',','.\n\n')[i%3],;i-=1
- or download this
i=298
while~-i:print i/3or 99,'bottle'+'s of beer on the wall.\n\n'[2<i<6:9+
+i%3*12]+'.X\n.G\noT atkoe tohnee sdtoowrne aanndd pbausys siotm
+ea rmoourned,,'[3%i+i%3*68::2],;i-=1
- or download this
i=297
while i:print-~i/3or 99,'bottle'+'s of beer on the wall.\n\n'[1<i<5:i%
+3*14^21]+'..\n\nGToa kteo otnhee dsotwonr ea nadn dp absusy isto m
+aer omuonrde,,'[i%3-2^-72|2%i::2],;i-=1
- or download this
print~$_/3|0||99," bottle",substr("s of beer on the wall.
X",6/$_%2,-4**($_%3)),(", ",$_<-4?".
Take one down and pass it around, ":".
Go to the store and buy some more, ")[$_%3-3]for-299..-3
- or download this
print-$_/3|0||99," bottle",("s"," of beer"," on the wall",".
")[5/$_%2..-$_%3+1],($_<-3?".
Take one down and pass it around, ":".
Go to the store and buy some more, ",", ")[-$_%3]for-298..-2
- or download this
298.downto(2){|i|$><<i/3%-99+99<<" bottle"+"s of beer on the wall.
"[5/i%i..8+i%3*12]<<[i>3?".
Take one down and pass it around, ":".
Go to the store and buy some more, ",", "][i%3]}
- or download this
298.downto(2){|i|$><<i/3%-99+99<<" bottle"+"s of beer on the wall.
"[5/i%i..8+i%3*12]<<".
Go to the store and buy some more, .
Take one down and pass it around, "[3%i*25/2+i%3*34,37]}
- or download this
eval"$><<%{#{a=b='#{n} bottl#{"es"[0,n]} of beer',' on the wall'}, #{b
+}.
\#{0<(n-=1)?'Take one down and pass it around':(n=99;'Go to the store
+and buy some more')}, #{a}.
};"*n=99
- or download this
eval %{puts"#{a='#{n} bottle#{n>1?:s:p} of beer on the wall'}, #{a[0,3
+0]}.
\#{(n-=1)<1?(n=99;'Go to the store and buy some more'):'Take one down
+and pass it around'}, #{a}.
"
}*n=99
- or download this
$_="Take one down and pass it around, #{~/s/;c=4-$.-=1," bottle#$& of
+beer"," on the wall"}.
#{c}, %s%s.
#$_"%c until/, 99\D+/;puts$'+"Go to the store and buy some more"+$&
- or download this
"Go to the store and buy some more"+(-99..-1).map{|n|", #{b=-n," bottl
+es"[0,6-n]+" of beer"," on the wall"}.
...
"%b}*"Take one down and pass it around"=~/
/;puts$'+$`
- or download this
# Based on emiltin.
eval"$><<%{#{a=b='#{n} bottl#{"es"[0,n]} of beer',' on the wall'}, #{b
+}.
\#{0<(n-=1)?'Take one down and pass it around':'Go to the store and bu
+y some more'%n=99}, #{a}.
};"*n=99
- or download this
# Based on J-_-L.
eval"$><<%{#{a=b='#{n} bottle#{n>1?:s:p} of beer',' on the wall'}, #{b
+}.
...
}
"*n=99
- or download this
/s/until@c=(@b=(++$n,bottle.$&,of,beer),on,the,wall),s/^/Take one down
+ and pass it around, @c.
@c, @b.
/,/, 99\D+/;print$'."Go to the store and buy some more$&"
- or download this
$_="Take one down and pass it around, #{~/s/;c=4-$.-=1," bottle#$& of
+beer"," on the wall"}.
#{c}, %s%s.
#$_"%c until/, 99\D+/;puts$'+"Go to the store and buy some more"+$&
- or download this
i=298
while~-i:print i/3or 99,'bottle'+'s of beer on the wall.\n\n'[5/i%i:i%
+3*28^9]+'.X\n.G\noT atkoe tohnee sdtoowrne aanndd pbausys siotm
+ea rmoourned,,'[i%3*69^3%i::2],;i-=1