Language F#
(lists and lambda's)
| Date: | 05/04/10 |
| Author: | Kyle Eppley |
| URL: | n/a |
| Comments: | 0 |
| Info: | http://www.microsoft.com |
| Score: |
module BeerList /// required for compile error in fsi
let a = " of beer " /// strings used
let b = "on the wall "
let c = "take one down pass it around "
let d = "Go to the store and buy some more, 99 bottles of beer on the wall.\n"
//build a list of bottle terms none to 99
let bottles = List.map (fun i -> i.ToString() + " bottles") [99..(-1)..2] @
["1 bottle";"no more bottles"]
let line1 = List.map (fun i -> i + a + b + i + a) bottles
//build line 1 from bottls and strings
let line2 = List.map (fun i -> c + i + a + b) bottles.Tail @ [d]
//build line 2 similarly
List.iter2 (fun i j -> printfn "%s\n%s\n" i j ) line1 line2
//output the lines interleafed
Download Source | Write Comment
Alternative Versions
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| Using list comprehension | Jörn Rönnow | 02/01/09 | 3 | |
| Tail Recursion Call | Simon Kang | 06/22/09 | 0 | |
| Cleaner still | Don Syme | 12/07/06 | 0 | |
| Recursive implementation | Alec Zorab | 07/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