2011-07-13 15:44:09 -07:00
|
|
|
/* -*- mode::rust;indent-tabs-mode::nil -*-
|
2010-09-20 22:08:28 +01:00
|
|
|
* Implementation of 99 Bottles of Beer
|
|
|
|
* http://99-bottles-of-beer.net/
|
|
|
|
*/
|
|
|
|
use std;
|
2011-05-17 20:41:41 +02:00
|
|
|
import std::int;
|
2011-09-01 17:27:58 -07:00
|
|
|
import std::str;
|
2010-09-20 22:08:28 +01:00
|
|
|
|
|
|
|
fn main() {
|
2011-07-27 14:19:39 +02:00
|
|
|
fn multiple(n: int) {
|
2011-09-02 15:34:58 -07:00
|
|
|
let nb: str = int::to_str(n, 10u);
|
|
|
|
let mb: str = int::to_str(n - 1, 10u);
|
|
|
|
log nb + " bottles of beer on the wall, " + nb + " bottles of beer,";
|
|
|
|
log "Take one down and pass it around, " + mb +
|
|
|
|
" bottles of beer on the wall.";
|
2011-06-15 11:19:50 -07:00
|
|
|
log "";
|
2011-07-27 14:19:39 +02:00
|
|
|
if n > 3 { be multiple(n - 1); } else { be dual(); }
|
2010-09-20 22:08:28 +01:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
fn dual() {
|
|
|
|
log "2 bottles of beer on the wall, 2 bottles of beer,";
|
|
|
|
log "Take one down and pass it around, 1 bottle of beer on the wall.";
|
|
|
|
log "";
|
|
|
|
be single();
|
2010-09-20 22:08:28 +01:00
|
|
|
}
|
2011-06-15 11:19:50 -07:00
|
|
|
fn single() {
|
|
|
|
log "1 bottle of beer on the wall, 1 bottle of beer,";
|
|
|
|
log "Take one down and pass it around, " +
|
|
|
|
"no more bottles of beer on the wall.";
|
|
|
|
log "";
|
|
|
|
be none();
|
|
|
|
}
|
|
|
|
fn none() {
|
|
|
|
log "No more bottles of beer on the wall, no more bottles of beer,";
|
|
|
|
log "Go to the store and buy some more, " +
|
2011-07-27 14:19:39 +02:00
|
|
|
"99 bottles of beer on the wall.";
|
2011-06-15 11:19:50 -07:00
|
|
|
log "";
|
|
|
|
}
|
|
|
|
multiple(99);
|
2011-08-19 15:16:48 -07:00
|
|
|
}
|