The MASM Forum

General => The Workshop => Topic started by: bluedevil on November 18, 2022, 10:22:20 PM

Title: 99 Bottles of Beer
Post by: bluedevil on November 18, 2022, 10:22:20 PM
Hello folks,

Did we write 99 bottles of beer coding quest before? Here is the lyrics:

Quote
The music
https://www.youtube.com/watch?v=FITjBet3dio
The music with some performance :D
https://www.youtube.com/watch?v=xCHYR3wRQLQ

I don't remember when I did run across this site 99 Bottles of Beer (https://www.99-bottles-of-beer.net/) but it seems fun.

So here is my snippet:


; _________________________________________________________________________
; initialized variables

.data
    sverse1 db "%s bottle%s of beer on the wall, %s bottle%s of beer.", 13, 10, 0
    sverse2 db "Take one down and pass it around, %s bottle%s of beer on the wall.", 13, 10, 13, 10, 0
    sverse3 db "Go to the store and buy some more, 99 bottles of beer on the wall.", 13, 10, 13, 10, 0
    nBeer   dq 99
    empty   db 0

; _________________________________________________________________________
; uninitialized variables

.data?
    CommandLine LPSTR ?
    hInstance   HINSTANCE ?
    NumArgs     DWORD ?
    sBeer1      db 3 dup(?)
    sBeer2      db 3 dup(?)

.code
main proc argc:DWORD,argv:LPSTR

    .while(nBeer {} -1)
        invoke sprintf, addr sBeer1,"%d", nBeer
        mov r15, nBeer
        dec r15
        invoke sprintf, addr sBeer2,"%d", r15
        .if nBeer == 2
            invoke printf, addr sverse1, addr sBeer1, "s", addr sBeer1, "s"
            invoke printf, addr sverse2, addr sBeer2, addr empty
           
        .elseif nBeer == 1
            invoke printf, addr sverse1, addr sBeer1, addr empty, addr sBeer1, addr empty
            invoke printf, addr sverse2, "no more", "s"
           
        .elseif nBeer == 0
            invoke printf, addr sverse1, "No more", "s", "no more", "s"
            invoke printf, addr sverse3
           
        .else
            invoke printf, addr sverse1, addr sBeer1, "s", addr sBeer1, "s"
            invoke printf, addr sverse2, addr sBeer2, "s"
        .endif

       
        sub nBeer,1
    .endw
   
    waitkey

    .exit
    ret

main endp
Title: Re: 99 Bottles of Beer
Post by: daydreamer on November 19, 2022, 05:12:31 AM
great :thumbsup:
Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 19, 2022, 05:55:25 AM
Thank you daydreamer.

I hope people share their version of this challenge. @jj2007 always share something original  :cool:
Title: Re: 99 Bottles of Beer
Post by: jj2007 on November 19, 2022, 11:03:57 AM
include \masm32\MasmBasic\MasmBasic.inc
  Init
  For_ ecx=99 To 2 Step -1
Print Str$("%i bottles of beer on the wall,", ecx), Str$(" %i bottles of beer.\n", ecx)
Print Str$("Take one down and pass it around, %i bottles of beer on the wall.\n\n", ecx-1)
  Next
  PrintLine "No more bottles of beer on the wall, no more bottles of beer."
  Inkey "Go to the store and buy some more, 99 bottles of beer on the wall."
EndOfCode


Output looks identical to me, please check and let me know if something is missing :cool:
Title: Re: 99 Bottles of Beer
Post by: jj2007 on November 19, 2022, 12:51:07 PM
What programming language has the shortest 'Hello World' program? (https://www.quora.com/What-programming-language-has-the-shortest-Hello-World-program/answer/Devin-McGinty)

Quotehq9+ is an esoteric language with only four commands: 'h' prints "hello, world", 'q' prints the program's source (Quine), '9' prints the lyrics to 99 bottles of beer, and '+' increments the accumulator. hq9+ was pretty much made as a joke to cheat at code golf. So the hello world is just:

h
Title: Re: 99 Bottles of Beer
Post by: TimoVJL on November 19, 2022, 07:30:44 PM
 :biggrin:

https://esolangs.org/wiki/HQ9%2B

Title: Re: 99 Bottles of Beer
Post by: jj2007 on November 19, 2022, 09:42:29 PM
Attached a 22 lines implementation of hq9+ :cool:

C++ needs 51 lines. There is a 15 lines Applesoft BASIC implementation at https://esolangs.org/wiki/HQ9%2B, but user Yes cheats with multiple commands on some lines. The Python implementation does it in 16 lines, though :thumbsup:
Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 20, 2022, 01:34:47 AM
Hello jj

In your first program you have missed the line which should start with 1 bottle of beer and you should print 1 bottle, not bottles!


2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 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.


In your second program there 's a redundant plural s after 1 bottles. In english people say 1 bottle, not bottles!


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

1 bottles of beer on the wall, 1 bottles of beer.
Take one down and pass it around, 0 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.


Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 20, 2022, 01:36:20 AM
Quote from: jj2007 on November 19, 2022, 12:51:07 PM
What programming language has the shortest 'Hello World' program? (https://www.quora.com/What-programming-language-has-the-shortest-Hello-World-program/answer/Devin-McGinty)

Quotehq9+ is an esoteric language with only four commands: 'h' prints "hello, world", 'q' prints the program's source (Quine), '9' prints the lyrics to 99 bottles of beer, and '+' increments the accumulator. hq9+ was pretty much made as a joke to cheat at code golf. So the hello world is just:

h

Esoteric languages always impress me! So if I did not get it wrong, hq9+ language's sole purpose is print hello world and the song lyrics of 99 bottles of beer?
Title: Re: 99 Bottles of Beer
Post by: zedd151 on November 20, 2022, 02:07:23 AM
@bluedevil, don't forget 'q' also prints the programs source.  :tongue:
Seems that any of these could be done in masm with macros.  :biggrin: 
Title: Re: 99 Bottles of Beer
Post by: TimoVJL on November 20, 2022, 02:40:37 AM
If external file is allowed
in Celse if(c[i]=='Q') system("type HQ9+.c"); :tongue:
22 lines of code
Title: Re: 99 Bottles of Beer
Post by: jj2007 on November 20, 2022, 08:33:23 AM
Quote from: bluedevil on November 20, 2022, 01:34:47 AM
Hello jj

In your first program you have missed the line which should start with 1 bottle of beer and you should print 1 bottle, not bottles!

You are right, that was sloppy coding :rolleyes:

include \masm32\MasmBasic\MasmBasic.inc
  Init
  Cls 7
  For_ ecx=4 To 1 Step -1
        .if ecx==1
                Print cfm$("1 bottle of beer on the wall, 1 bottle of beer.\n")
        .else
                Print Str$("%i bottles of beer on the wall,", ecx), Str$(" %i bottles of beer.\n", ecx)
        .endif
        .if ecx==2
                Print cfm$("Take one down and pass it around, 1 bottle of beer on the wall.\n\n")
        .else
                Print Str$("Take one down and pass it around, %i bottles of beer on the wall.\n\n", ecx-1)
        .endif
  Next
  PrintLine "No more bottles of beer on the wall, no more bottles of beer."
  Inkey "Go to the store and buy some more, 99 bottles of beer on the wall."
EndOfCode


4 bottles of beer on the wall, 4 bottles of beer.
Take one down and pass it around, 3 bottles of beer on the wall.

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 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, 0 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.
Title: Re: 99 Bottles of Beer
Post by: zedd151 on November 21, 2022, 12:46:04 AM
Now we need a line by line scrolling text of the song, accompanied by a synced MP3 of it playing in the background sung by a group of drunkards.  :toothy:  Beyond my coding capabilities, btw.  :tongue:
Title: Re: 99 Bottles of Beer
Post by: TimoVJL on November 21, 2022, 02:30:16 AM
I saw mentioned a compressed text strings, so we have use pen and paper for it :azn:
Perhaps repeated parts can connected.

EDIT
https://stackoverflow.com/questions/32576203/trying-to-code-the-99-bottles-of-beer-song
Title: Re: 99 Bottles of Beer
Post by: daydreamer on November 21, 2022, 02:47:09 AM
Quote from: zedd151 on November 21, 2022, 12:46:04 AM
Now we need a line by line scrolling text of the song, accompanied by a synced MP3 of it playing in the background sung by a group of drunkards.  :toothy:  Beyond my coding capabilities, btw.  :tongue:
I thought that was made Saturday evening while party record singing, and change text from "press any key" to "don't sing off key"  :tongue:
:greenclp:

I hope this challenge is open to think outside the box,99 bottles with a twist, not create program with exact same output?
here is my way,english isnt my native language


Title: Re: 99 Bottles of Beer
Post by: jj2007 on November 21, 2022, 03:50:44 AM
Quote from: daydreamer on November 21, 2022, 02:47:09 AMI hope this challenge is open to think outside the box,99 bottles with a twist, not create program with exact same output?
here is my way,english isnt my native language

I am tempted to write a macro that converts 25 to "twenty-five" :tongue:

    switch seconddigit
    case 2
    print "twenty"
    case 3
    print "thirty"
    case 4
    print "forty"
    case 5
    print "fifty"
Title: 99 Bottles of Beer - text version
Post by: jj2007 on November 21, 2022, 11:55:36 AM
There it is (http://masm32.com/board/index.php?topic=10499.0), the NumberAsText$ macro :tongue:

Ninety-Nine bottles of beer on the wall, ninety-nine bottles of beer.
Take one down and pass it around, ninety-eight bottles of beer on the wall.

Ninety-Eight bottles of beer on the wall, ninety-eight bottles of beer.
Take one down and pass it around, ninety-seven bottles of beer on the wall.
...
Two bottles of beer on the wall, two bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

One bottle of beer on the wall, one bottle of beer.
Take one down and pass it around,  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.


include \masm32\MasmBasic\MasmBasic.inc
  Init
  For_ ecx=99 To 1 Step -1
.if ecx==1
Print cfm$("One bottle of beer on the wall, one bottle of beer.\n")
.else
Print TitleCase$(NumberAsText$(ecx))
PrintLine " bottles of beer on the wall, ", NumberAsText$(ecx), " bottles of beer."
.endif
.if ecx==2
Print cfm$("Take one down and pass it around, 1 bottle of beer on the wall.\n\n")
.else
lea eax, [ecx-1]
PrintLine "Take one down and pass it around, ", NumberAsText$(eax), cfm$(" bottles of beer on the wall.\n")
.endif
  Next
  PrintLine "No more bottles of beer on the wall, no more bottles of beer."
  Inkey "Go to the store and buy some more, 99 bottles of beer on the wall."
EndOfCode
Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 21, 2022, 05:16:16 PM
Quote from: daydreamer on November 21, 2022, 02:47:09 AM
Quote from: zedd151 on November 21, 2022, 12:46:04 AM
Now we need a line by line scrolling text of the song, accompanied by a synced MP3 of it playing in the background sung by a group of drunkards.  :toothy:  Beyond my coding capabilities, btw.  :tongue:
I thought that was made Saturday evening while party record singing, and change text from "press any key" to "don't sing off key"  :tongue:
:greenclp:

I hope this challenge is open to think outside the box,99 bottles with a twist, not create program with exact same output?
here is my way,english isnt my native language

Hello @daydreamer
I love the way do it. But you have missed things?
1. New lines. After two line there should be a newline
2. You should decrement bottle number in the second line, look:

three  bottles of beer on the wall. three  bottles of beer.
take one down and pass it around. three  bottles of beer on the wall

Look at your second line, you took one and pass it around[the bottle], and you have still three bottles. It should be two bottles.
Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 21, 2022, 05:18:39 PM
Quote from: bluedevil on November 21, 2022, 05:16:16 PM
Quote from: daydreamer on November 21, 2022, 02:47:09 AM
Quote from: zedd151 on November 21, 2022, 12:46:04 AM
Now we need a line by line scrolling text of the song, accompanied by a synced MP3 of it playing in the background sung by a group of drunkards.  :toothy:  Beyond my coding capabilities, btw.  :tongue:
I thought that was made Saturday evening while party record singing, and change text from "press any key" to "don't sing off key"  :tongue:
:greenclp:

I hope this challenge is open to think outside the box,99 bottles with a twist, not create program with exact same output?
here is my way,english isnt my native language

Hello @daydreamer
I love the way do it. But you have missed things?
1. New lines. After two line there should be a newline
2. You should decrement bottle number in the second line, look:

three  bottles of beer on the wall. three  bottles of beer.
take one down and pass it around. three  bottles of beer on the wall

Look at your second line, you took one and pass it around[the bottle], and you have still three bottles. It should be two bottles.

@jj2007, this is beautiful, you only missed "no more" here:

One bottle of beer on the wall, one bottle of beer.
Take one down and pass it around,  bottles of beer on the wall.
                                                  ^
                                             no more
Title: 99 bottles of sake
Post by: daydreamer on November 23, 2022, 05:44:28 AM
Hi
I corrected some and progressed with 99 bottles of sake :greenclp:
Title: Re: 99 bottles of sake
Post by: bluedevil on November 23, 2022, 07:06:52 AM
Quote from: daydreamer on November 23, 2022, 05:44:28 AM
Hi
I corrected some and progressed with 99 bottles of sake :greenclp:

sake? I am in. But where is the code. Let us try the codes.
Title: Re: 99 Bottles of Beer
Post by: hutch-- on November 23, 2022, 10:50:12 AM
 :biggrin:

Try is with 99 bottles of Raki but I doubt you would make it to bottle 99.  :tongue:
Title: Re: 99 bottles of sake
Post by: daydreamer on November 24, 2022, 01:59:36 AM
Quote from: bluedevil on November 23, 2022, 07:06:52 AM
Quote from: daydreamer on November 23, 2022, 05:44:28 AM
Hi
I corrected some and progressed with 99 bottles of sake :greenclp:

sake? I am in. But where is the code. Let us try the codes.
Updated previous zip file with two proc's
Japanese version of numbers to text and alternative 99 bottles of sake in karaoke bar
Title: Re: 99 Bottles of Beer
Post by: bluedevil on November 24, 2022, 02:01:41 AM
Quote from: hutch-- on November 23, 2022, 10:50:12 AM
:biggrin:

Try is with 99 bottles of Raki but I doubt you would make it to bottle 99.  :tongue:

:eusa_dance:
When I was younger, yes I can finish the 99th bottle(but only the 99th), but now i could not finish even only one!  :bgrin: thanks for reminding :D