Language C#
(v3.0 Easy Functional Recursive)
Date: | 08/04/09 |
Author: | Yelinna Pulliti Carrasco |
URL: | http://toyscaos.tripod.com |
Comments: | 0 |
Info: | http://msdn.microsoft.com/en-us/vcsharp/aa336745.aspx |
Score: | (2.00 in 4 votes) |
using System; using System.Text; namespace Bottles_of_Beer { class Program { delegate int BottlesBeer(BottlesBeer B, int n); static void Main(string[] args) { Func<int, int> BeerEnd = n => { Console.WriteLine( "Take one down and pass it around, no more bottles of beer on the wall."); Console.WriteLine( "No more bottles of beer on the wall, no more bottles of beer."); Console.WriteLine( "Go to the store and buy some more, {0} bottles of beer on the wall.", n + 98); return 0; }; Func<int, int> Beer = n => { string s = n > 2 ? String.Concat( "Take one down and pass it around, ", (n - 1).ToString(), " bottles of beer on the wall.") : String.Concat( "Take one down and pass it around, ", (n - 1).ToString(), " bottle of beer on the wall."); Console.WriteLine(s); return 0; }; BottlesBeer B2 = (b, i) => { string s = i >= 2 ? String.Concat( (i).ToString(), " bottles of beer on the wall, ", (i).ToString(), " bottles of beer on the wall.") : String.Concat( (i).ToString(), " bottle of beer on the wall, ", (i).ToString(), " bottle of beer on the wall."); Console.WriteLine(s); if (i == 1) { BeerEnd(i); return 0; } else { Beer(i); return i = b(b, i - 1); } }; B2(B2, 99); // you can do: int b0 = B2(B2,99) 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 | |
Uses Linq | Sudipta | 11/19/10 | 0 | |
Shows new features of C# 2.0. | Bradley Tetzlaff | 11/24/05 | 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