1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. We've had very few donations over the year. I'm going to be short soon as some personal things are keeping me from putting up the money. If you have something small to contribute it's greatly appreciated. Please put your screen name as well so that I can give you credit. Click here: Donations
    Dismiss Notice

99 bottles of beer on the wall (lolwtfomgbbq)

Discussion in 'General Discussions' started by ejkwt, Aug 4, 2011.

  1. ejkwt

    ejkwt Vertical

    There's a website out there.. how many ways can you program (any language) to spit out the song

    "99 bottles of beer on the wall, 99 bottles of beer.
    Take one down and pass it around, 98 bottles of beer on the wall.

    98 bottles of beer on the wall, 98 bottles of beer.
    Take one down and pass it around, 97 bottles of beer on the wall.

    ...

    2 bottles of beer on the wall, 2 bottles of beer.
    Take one down and pass it around, 1 bottle of beer on the wall.

    1 bottle of beer on the wall, 1 bottle of beer.
    Take one down and pass it around, no more bottles of beer on the wall.

    No more bottles of beer on the wall, no more bottles of beer.
    Go to the store and buy some more, 99 bottles of beer on the wall."

    Here's a a simple one in Ruby:

    song = ""
    99.downto(1) do |i|
    s = i>=2 ? "s" : ""
    s2 = i-1==1? "" : "s"
    song += "#{i} bottle#{s} of beer on the wall, #{i} bottle#{s} of beer.\n"
    song += "Take one down and pass it around, #{s==""? "no more" : i-1} bottle#{s2} of beer on the wall.\n"
    end
    song += "No more bottles of beer on the wall, no more bottles of beer."
    song += "Go to the store and buy some more, 99 bottles of beer on the wall."
    puts song
     
  2. Zen

    Zen Very Tilted

    Location:
    London
    I think I just had a geekgasm :D
     
  3. ejkwt

    ejkwt Vertical

    ^.^ Why, thank you. I think its more fun when you do the crazier ways.. arrays, assoc's, and gsubs.. :D
     
  4. Zen

    Zen Very Tilted

    Location:
    London
    I bow down and am not worthy.

    I reached my logic 'ceiling' writing simple if>then .. then .. then endif texts for booting and loading ramdisc in the old Atari 1040.

    Still feel proud of that, er .. and also to 'know', albeit cringingly, my ignorance ... that I'd not be able to tell the difference between a gsub and a strangely filled bread roll.

    Hmm ... I'm sure I've got in the back of my mind some example of 'codified' music. I'll have a sleep and see if it emerges :)
     
  5. ejkwt

    ejkwt Vertical

    Hey that sounds pretty cool already -- everything just boils down to basic operations and memory operations anyways.

    Here's another method in Ruby since no one else has posted one; it's more fun using arrays, string subs, and Array.zip:

    a = (1..99).collect{|i|i}.reverse.push("No more").map{|i| "#{i} bottles of beer on the wall, #{i.to_s.downcase} bottles of beer."}
    b = (1..98).collect{|i|i}.reverse.push("no more").map{|i| "Take one down and pass it around, #{i} bottles of beer on the wall.\n"}
    a[a.length-2].gsub!(/bottles/,"bottle")
    b[b.length-2].gsub!(/bottles/,"bottle")
    b.push("Go to the store and buy some more, 99 bottles of beer on the wall.")
    puts a.zip(b).join("\n")
     
  6. MSD

    MSD Very Tilted

    Location:
    CT
    I prefer a Mechanical Turk approach to the problem. Compilers aren't all that good at passing beer around, and God forbid you splash a bit onto them when you're singing enthusiastically.
     
    • Like Like x 2
  7. Baraka_Guru

    Baraka_Guru Möderätor Staff Member

    Location:
    Toronto
    Q.E.D.
     
  8. ejkwt

    ejkwt Vertical

    .gsub(/compiler/i,"Interpreter")

    XD