Terje Isaksen Developer blog

2011-06-23 (Thursday)

600+ different programming languages

Filed under: Developing — Terje Isaksen @ 12:58
Tags:

http://99-bottles-of-beer.net/

Every language from A+ to ZZT

One C# version is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _99Bottlez
{
    class Program
    {
        static void Main(string[] args)
        {
            int countOfBottles = 10;
            string lineTemplate = @"{X} bottles of beer on the wall, {X} bottles 
                                  of beer. Take one down and pass it around, {Y} 
                                  bottles of beer on the wall.";

            string lastLine =  @"No more bottles of beer on the wall, no more   
                               bottles of beer.Go to the store and buy some 
                               more, {X} bottles of beer on the wall.";

            List<string> songLines = new List<string> ();
            Enumerable.Range(1, countOfBottles)
                .Reverse()
                .ToList()
                .ForEach
                 (c => songLines.Add(lineTemplate.Replace("{X}", 
                 c.ToString()).Replace("{Y}", (c-1)!=0?(c - 1).ToString():@" No 
                 more bottles of beer on the wall.")));

            //Add the last line
            songLines.Add(lastLine.Replace("{X}", countOfBottles.ToString()));

            songLines.ForEach(c => Console.WriteLine(c));
            Console.ReadLine();
        }
    }
}
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: