r/dailyprogrammer • u/nottoobadguy • Feb 16 '12
[2/16/2012] Challenge #8 [easy]
write a program that will print the song "99 bottles of beer on the wall".
for extra credit, do not allow the program to print each loop on a new line.
14
Upvotes
5
u/EnterpriseProgrammer Feb 16 '12
Java
1
u/StorkBaby 0 0 Feb 16 '12
Guys, I cannot find any information on how to spoiler text and it's not in the formatting help for this text entry, would someone please put this into the formatting help as I prefer putting the code in comments to pastebin if it's short.
3
u/[deleted] Feb 16 '12 edited Feb 16 '12
C++
3
u/SirNikkolas Feb 16 '12
Java
}
2
u/eruonna Feb 16 '12 edited Feb 16 '12
Common Lisp, format again:
It's kind of silly not to do the printing in the same loop that generates the range. Why doesn't CL have a range function, anyway?
2
u/Krissam Feb 16 '12 edited Feb 16 '12
C# (Don't remember the exact lyrics lol :S)
Also, extra credit :P
2
u/[deleted] Feb 16 '12
Reference. It contains implementations for just about any language you can imagine.
2
u/cooper6581 Feb 16 '12
Python
2
u/BobDorian Feb 17 '12
C++
2
u/spunos Feb 17 '12
If writing code is like creating art, then I suppose you could say I'm in my experimental phase...
Python 3:
1
u/nikoma Feb 16 '12 edited Feb 16 '12
python 3.2 code (no new lines):
1
u/[deleted] Feb 16 '12
It hardly seems fair that I get extra credit in javascript when making each loop on it's own line is more work...
1
u/thatrandomusername Feb 16 '12
Javascript?
Also, when it gets to one it won't say "1 bottles of beer", instead "1 bottle of beer".
1
u/stiggz Feb 16 '12 edited Feb 16 '12
in php:
1
u/FataOne 0 0 Feb 16 '12
In C: int main (void) { int bottle;
The extra credit could easily be achieved by removing the "\n" from the printf statement and adding a space.
1
u/PrivatePilot Feb 16 '12
Ruby
1
u/donalmacc 0 0 Feb 16 '12
My First attempt at any of these, in Lua (Just started yesterday, coming from C++) No extra credit though
1
u/robin-gvx 0 2 Feb 16 '12
Déjà Vu, two versions, without and with extra credit:
http://hastebin.com/raw/homubayuwe
1
u/scibuff Feb 16 '12
only if I ever heard of that song ...
1
u/[deleted] Feb 17 '12
Here's mine in Java.
http://pastie.org/3398267
1
u/jnaranjo Feb 17 '12
Same line printing in python2.7
bottles = [] count = 100 for bottle in range(1,101): bottles.append("%d bottles of beer on the wall\t" % count) count -= 1
print ''.join(bottles)
1
u/[deleted] Feb 17 '12 edited Feb 17 '12
1
u/SleepyTurtle Feb 17 '12 edited Feb 17 '12
python 2.7. set it up to sing song for any number of bottles without adding an extra variable.
1
u/UnreasonableSteve Feb 17 '12
http://pastebin.com/f7RiZm8L Done in PHP, don't quite know what the extra credit is about, I assume it's meant to make you append each line to a string? Anyway PHP doesn't add newlines by default so it's hardly extra to keep the newlines off...
1
u/Captain_Sabatini Feb 17 '12 edited Feb 17 '12
I didn't see anyone doing it using recursion so I will, just for the hell of it.
EDIT: I initially wrote this to work in ascending but I changed to descending so I had to switch print and recursive call.
1
u/Crystal_Cuckoo Feb 17 '12
Python:
1
u/drb226 0 0 Feb 17 '12
Haskell
Output (no newlines, prepare to use your horizontal scrollbar): http://ideone.com/Rlah5
1
u/[deleted] Feb 17 '12
Ruby.
1
u/[deleted] Feb 17 '12
Java
1
u/heliolatry Feb 17 '12
Java:
1
u/kuzux 0 0 Feb 17 '12
in clojure; as a generic "number containers of beverage on the wall" so that you can call it like (sing 99 bottles of beer) or (sing 42 shots of tequila)
1
u/CorrosiveMonkey Mar 23 '12
Prolog. Doesn't handle the pluralisation correctly.
1
u/savagecub Apr 17 '12
C++
// beer on the wall.cpp : main project file.
include "stdafx.h"
include <iostream>
include <string>
include <cctype>
include <fstream>
using namespace std;
int main() { int beer = 100;
}
1
u/Stock_Childhood7303 Apr 05 '25
1
u/ragtag_creature Oct 11 '22
Written with R
-2
u/irlKryst Feb 16 '12
Did you take this idea from my blog? O_O
2
u/[deleted] Feb 16 '12
[removed] — view removed comment