Syntactic Confectionery Delight PerlMonks

Re: Drunk on golf: 99 Bottles of Beer

by eyepopslikeamosquito (Chancellor)
 on Jun 12, 2011 at 07:25 UTC ( #909285=note: print w/replies, xml ) Need Help??

```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"
```
```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())
```
```n and"Take one down and pass it around"or"Go to the store and buy some
+ more"
```
```"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!
```
```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
```
```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
```
```'..\n\nGToa kteo  otnhee  dsotwonr ea nadn dp absusy  isto maer omuonr
+de,,'[(i>3)+i%3*68::2]
```
```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
```
```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
```
```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
```
```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
```
```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
```
```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]}
```
```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]}
```
```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

};"*n=99
```
```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
```
```\$_="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"+\$&
```
```"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\$'+\$`
```
```# 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
```
```# Based on J-_-L.
eval"\$><<%{#{a=b='#{n} bottle#{n>1?:s:p} of beer',' on the wall'}, #{b
+}.
...

}
"*n=99
```
```/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\$&"
```
```\$_="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"+\$&
```
```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
```

Create A New User
Node Status?
node history
Node Type: note [id://909285]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2019-10-20 16:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2019 the site I miss most is:

Results (50 votes). Check out past polls.

Notices?