General > The Campus

99 Bottles of Beer

(1/5) > >>

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

--- End quote ---

I don't remember when I did run across this site 99 Bottles of Beer but it seems fun.

So here is my snippet:


--- Code: ---; _________________________________________________________________________
; 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

--- End code ---

daydreamer:
great :thumbsup:

bluedevil:
Thank you daydreamer.

I hope people share their version of this challenge. @jj2007 always share something original  :cool:

jj2007:

--- Code: ---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
--- End code ---

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?


--- Quote ---hq9+ 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
--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version