Language C#
(Uses Linq)
Date: | 11/19/10 |
Author: | Sudipta |
URL: | sudipta.posterous.com |
Comments: | 0 |
Info: | n/a |
Score: | (2.90 in 21 votes) |
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(); } } }
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Concise, using C# 3.5 features | Jeff Dietrich | 10/26/07 | 14 | |
2 | Paul M. Parks | 04/20/05 | 9 | |
C# Gratuitously Functional | Paul Stancer | 04/14/09 | 1 | |
corporate style | veteran corporate coder | 08/16/09 | 0 | |
5 | Mark Hurley | 05/31/05 | 0 | |
Shows new features of C# 2.0. | Bradley Tetzlaff | 11/24/05 | 0 | |
v3.0 Easy Functional Recursive | Yelinna Pulliti Carrasco | 08/04/09 | 0 |
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments