using System;
using System.Collections.Generic;
using System.Linq;
namespace Bottles99
{
///
/// A gratuitously functional implementation of the 99 bottle of beer on the wall program.
///
static class Program
{
static void ForEach(this IEnumerable items, Action action)
{
foreach (var item in items) action(item);
}
static void Main(string[] args)
{
Console.WriteLine("99 bottles of beer on the wall, 99 bottles of beer.");
Func bottle = (v, upper) =>
{
return string.Format("{0} bottle{1}",
(v == 0) ? ((upper ? "N" : "n") + "o more"):v.ToString() , ((v == 1) ? "" : "s"));
};
Enumerable.Range(0, 99).Reverse()
.ForEach(i =>
{
Console.WriteLine(string.Format(
"Take one down and pass it around, {0} of beer on the wall.\r\n",
bottle(i, false)));
Console.WriteLine(string.Format(
"{0} of beer on the wall, {1} of beer.",
bottle(i, true), bottle(i, false)));
});
Console.WriteLine("Go to the store and buy some more, 99 bottles of beer on the wall.");
Console.ReadLine();
}
}
}