Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Ruby

(minimal version)

Date:05/18/05
Author:Anonymous
URL:n/a
Comments:3
Info:n/a
Score: (3.06 in 108 votes)
#Writes down an exact copy of the song on this site

99.downto(0){|b|puts "#{b==0?'No more b':"#{b} B"}ottle#{'s'if b!=1} of beer on the wall,
#{b==0?'No more':b} bottle#{'s'if b!=1} of beer.#{b==0?".. Go to the store and buy some more...\n99
bottles of beer.":"\nTake one down and pass it around, #{b-1} bottle#{'s'if b!=2} of beer on the
wall.\n\n"}"}

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Using continuations, singleton classesVictor Borja09/15/064
object-oriented versionMike Gertz04/20/052
In wordsDaniel Straight07/10/061
shows inheritance, iterators, yield, etcKian Wright06/10/050
Readably re-opening Integer, teetotallerEric Budd01/06/080
wall-based OO versionKevin Baird07/07/052
alternative versionGreg T.05/18/0510
monkeypatch and anonymous procsJ. B. Rainsberger04/04/070

Comments

>>  Anonymous said on 06/01/05 15:07:18

Anonymous Seems the layout got mixed up when submitting.
Replace the linebreaks in the code with spaces and it works correctly.

>>  Jannis Harder said on 08/18/06 20:47:11

Jannis Harder This is far from minimal. Take a look at http://codegolf.com/competition/index/1

>>  C.G.E. said on 10/12/06 15:25:01

C.G.E. This is unfortunately nowhere near being a minimal version, as Jannis Harder reported. This is somewhat better, trimming off 101 bytes, though still 9% bigger than the smallest Ruby entry. As of posting this, it is in the top 15 results on codegolf for Ruby. Please don't abuse it.

def c
"#{$n} bottle#{'s'if$n>1} of beer on the wall"end
($n=99).times{puts"#{c}, #{c[0..-13]}.
#{$n<2?"Go to the store and buy some more":"Take one down and pass it around"}, #{$n=($n-2)%99+1;c}.

"}

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: