News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

99 Bottles of Beer

Started by bluedevil, November 18, 2022, 10:22:20 PM

Previous topic - Next topic

bluedevil

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 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
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

daydreamer

my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

bluedevil

Thank you daydreamer.

I hope people share their version of this challenge. @jj2007 always share something original  :cool:
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

jj2007

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:

jj2007

What programming language has the shortest 'Hello World' program?

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

TimoVJL

 :biggrin:

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

May the source be with you

jj2007

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:

bluedevil

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.


..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

bluedevil

Quote from: jj2007 on November 19, 2022, 12:51:07 PM
What programming language has the shortest 'Hello World' program?

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?
..Dreams make the future
But the past never lies..
BlueDeviL // SCT
My Code Site:
BlueDeviL Github

zedd151

@bluedevil, don't forget 'q' also prints the programs source.  :tongue:
Seems that any of these could be done in masm with macros.  :biggrin: 

TimoVJL

If external file is allowed
in Celse if(c[i]=='Q') system("type HQ9+.c"); :tongue:
22 lines of code
May the source be with you

jj2007

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.

zedd151

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:

TimoVJL

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
May the source be with you

daydreamer

#14
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


my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding