aboutsummaryrefslogtreecommitdiff
path: root/src/test/bench/99-bottles/99bob-tail.rs
blob: 202b653b78f79b281c2cf8362a383d216bd24be9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* -*- mode::rust;indent-tabs-mode::nil -*- 
 * Implementation of 99 Bottles of Beer
 * http://99-bottles-of-beer.net/
 */
use std;
import std::_int;
import std::_str;

fn main() {
  fn multiple(int n) {
    let str nb =  _int::to_str(n, 10u);
    let str mb =  _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.";
    log "";
    if (n > 3) {
      be multiple(n - 1);
    }
    else {
      be dual();
    }
  }
  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();
  }
  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, 99 bottles of beer on the wall.";
    log "";
  }
  multiple(99);
}