School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,084 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,275 people online right now. Registration is fast and FREE... Join Now!




Unique ways to accomplish a task. (Task 2)

 

Unique ways to accomplish a task. (Task 2), 99 Bottles Of Beer

AdamSpeight2008

11 Jun, 2009 - 03:55 PM
Post #1

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
Your task if you choice to accept is reproduce the song. Just for <beep> & giggles.
QUOTE(99 Bottles of beer song)

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

etc.

1 bottles of beer on the wall, 1 bottle of beer.
Take one down 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 buy some more, 99 bottles of beer on the wall.


Constraints: You can't use bottle(s)

I'll start with mine
CODE

Module BottlesOfBeer

Sub Main()
  Dim Bottle = Function(b) " bottle" & If(b > 1, "s", "") & " of beer"
  Dim GotBeer = Function(b) If(b > 0, b & Bottle(b), "No more bottles of beer")
  Dim OnWallLine = Function(b, r) GotBeer(b) & " on the wall" & If(r >= 0, ", " & GotBeer(b), "") & "." & vbNewLine
  Dim TakeOneDownLine = Function(b) If(b >= 0, "Take one down and pass it around, " & OnWallLine(b, -1), "Go to the store and buy some more, " & OnWallLine(99, -1))
  Dim Verses = (From i In Enumerable.Range(0, 100).Reverse Select CStr(OnWallLine(i, 0) & TakeOneDownLine(i - 1))).ToArray
  Array.ForEach(Of String)(Verses, (New Action(Of String)(AddressOf PrintVerse)))
End Sub
Private Sub PrintVerse(ByVal v As String)
  Console.WriteLine(v)
  Console.ReadLine
End Sub

End Module



Happy Coding

This post has been edited by AdamSpeight2008: 11 Jun, 2009 - 03:57 PM

User is online!Profile CardPM
+Quote Post


egof

RE: Unique Ways To Accomplish A Task. (Task 2)

15 Jun, 2009 - 07:04 AM
Post #2

D.I.C Head
Group Icon

Joined: 27 Mar, 2009
Posts: 96



Thanked: 12 times
Dream Kudos: 100
My Contributions
CODE

Sub Main()
     PrintVerse(99)
End Sub
Sub PrintVerse(ByVal v As Integer)
    If v > 1 Then
        Console.WriteLine(String.Format("{0} bottles of beer on the wall, {0} bottles of beer.", v))
        Console.WriteLine(String.Format("Take one down pass it around, {0} bottle of beer on the wall.", v - 1))
        PrintVerse(v - 1)
    Else
        Console.WriteLine("1 bottle of beer on the wall, 1 bottle of beer.")
        Console.WriteLine("Take one down pass it around, No more bottles of beer on the wall.")
        Console.WriteLine("Go to the store buy some more, 99 bottles of beer on the wall.")
    End If
End Sub


This post has been edited by egof: 15 Jun, 2009 - 12:14 PM
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Unique Ways To Accomplish A Task. (Task 2)

15 Jun, 2009 - 11:51 AM
Post #3

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
That's Good but it misses out the last verse.
User is online!Profile CardPM
+Quote Post

egof

RE: Unique Ways To Accomplish A Task. (Task 2)

15 Jun, 2009 - 12:15 PM
Post #4

D.I.C Head
Group Icon

Joined: 27 Mar, 2009
Posts: 96



Thanked: 12 times
Dream Kudos: 100
My Contributions
Oops, got it fixed
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008

RE: Unique Ways To Accomplish A Task. (Task 2)

15 Jun, 2009 - 12:27 PM
Post #5

The Bandido Coder
Group Icon

Joined: 29 May, 2008
Posts: 2,734



Thanked: 160 times
Dream Kudos: 3925
Expert In: vb.net, LINQ

My Contributions
The last verse is.
QUOTE

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

User is online!Profile CardPM
+Quote Post

jase81

RE: Unique Ways To Accomplish A Task. (Task 2)

24 Jun, 2009 - 06:12 PM
Post #6

D.I.C Head
**

Joined: 2 Mar, 2009
Posts: 59



Thanked: 1 times
My Contributions
VB

Private Sub bottles()
Dim x, y As Integer
Dim numberOfBottles = 5

Do Until numberOfBottles < 0
Dim bottles As String = "x bottles of beer on the wall, x bottles of beer. Take one down pass it around, y bottles of beer on the wall."
If numberOfBottles > 2 Then
x = numberOfBottles
y = numberOfBottles - 1
bottles = bottles.Replace("x", x.ToString)
bottles = bottles.Replace("y", y.ToString)
ElseIf numberOfBottles = 2 Then
bottles = "2 bottles of beer on the wall, 2 bottles of beer. Take one down pass it around, 1 bottle of beer on the wall."
ElseIf numberOfBottles = 1 Then
bottles = "1 bottle of beer on the wall, 1 bottle of beer. Take one down pass it around, no more bottles of beer on the wall."
Else
bottles = "No more bottles of beer on the wall, No more bottles of beer. Go to the store buy some more, 99 bottles of beer on the wall."
numberOfBottles = 100 ' make infinite loop'
End If
numberOfBottles -= 1
MsgBox(bottles.ToString)
Loop

End Sub

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:41AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month