12345678910111213141516171819202122232425262728293031 |
- module BeerSong
-
- let stateLine n =
- if n > 1
- then sprintf "%d bottles of beer on the wall, %d bottles of beer." n n
- else if n = 1
- then "1 bottle of beer on the wall, 1 bottle of beer."
- else "No more bottles of beer on the wall, no more bottles of beer."
-
- let takeDownLine n =
- if n > 2
- then sprintf "Take one down and pass it around, %d bottles of beer on the wall." (n - 1)
- else if n = 2
- then "Take one down and pass it around, 1 bottle of beer on the wall."
- else if n = 1
- then "Take it down and pass it around, no more bottles of beer on the wall."
- else "Go to the store and buy some more, 99 bottles of beer on the wall."
-
- let verse (n: int) (left: int) =
- if left > 1 then [ stateLine n; takeDownLine n; "" ] else [ stateLine n; takeDownLine n ]
-
- let rec beerLines (n: int) (left: int): list<string> =
- let newBottles = if n = 0 then 99 else n - 1 // wrap around when get to 0
- if left > 0 && n >= 0 then
- List.concat
- [ (verse n left)
- (beerLines newBottles (left - 1)) ]
- else
- []
-
- let recite (startBottles: int) (takeDown: int) = beerLines startBottles takeDown
|