Wednesday, January 11, 2012

I like free beer!

Did you know about http://99-bottles-of-beer.net?
They list programs generating lyrics for a song about beer in 1440 different programming languages (it will be 1441 very soon ;-)). These are the lyrics to generate.

So here is a version written in Xtend:


It uses a couple of interesting features:
Seriously, I think this is one of the most concise and readable versions. Compare yourself.

2 comments:

  1. ... nice. F#-Version is pretty elegant too:


    let theBottleSong =
    let strSong = new System.Text.StringBuilder()
    let append (s:string) = strSong.Append(s) |> ignore

    for i = 99 downto 0 do
    if (i = 0) then
    append "\n\nNo more bottles of beer on the wall, no more bottles of beer.\nGo to the store and buy some more, 99 bottles of beer on the wall."
    else
    let x = i - 1
    let plural = if (i = 1) then "" else "s"

    append (sprintf "\n%d bottle%s of beer on the wall, %d bottle%s" i plural i plural)
    append "\nTake one down and pass it around, "

    match x with
    | 1 -> append "1 bottle "
    | 0 -> append " no more bottles "
    | _ -> append (sprintf "%d bottles of beer on the wall.\n" x)

    strSong.ToString()

    printfn "%s\n" theBottleSong

    ReplyDelete