aboutsummaryrefslogtreecommitdiff
path: root/beer-song/src/lib.rs
diff options
context:
space:
mode:
authorFederico Igne <git@federicoigne.com>2020-12-26 17:48:38 +0000
committerFederico Igne <git@federicoigne.com>2021-11-03 18:55:08 +0000
commit02481656966b0a8dfc95cf3c22bcc049660ff7d4 (patch)
tree8e39798fcaf27931d91c2088423fd4e97adcfc2d /beer-song/src/lib.rs
parent4e2052c4d792540c2f742b2c2a081b11117ed41d (diff)
downloadexercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.tar.gz
exercism-02481656966b0a8dfc95cf3c22bcc049660ff7d4.zip
Move Rust exercises in a subdirectory
Diffstat (limited to 'beer-song/src/lib.rs')
-rw-r--r--beer-song/src/lib.rs20
1 files changed, 0 insertions, 20 deletions
diff --git a/beer-song/src/lib.rs b/beer-song/src/lib.rs
deleted file mode 100644
index 990fbbf..0000000
--- a/beer-song/src/lib.rs
+++ /dev/null
@@ -1,20 +0,0 @@
1use itertools::Itertools;
2
3pub fn verse(n: u32) -> String {
4 match n {
5 0 => format!( "No more bottles of beer on the wall, no more bottles of beer.\n\
6 Go to the store and buy some more, 99 bottles of beer on the wall.\n"),
7 1 => format!( "1 bottle of beer on the wall, 1 bottle of beer.\n\
8 Take it down and pass it around, no more bottles of beer on the wall.\n"),
9 2 => format!( "2 bottles of beer on the wall, 2 bottles of beer.\n\
10 Take one down and pass it around, 1 bottle of beer on the wall.\n"),
11 _ => format!( "{} bottles of beer on the wall, {} bottles of beer.\n\
12 Take one down and pass it around, {} bottles of beer on the wall.\n",
13 n, n, n - 1)
14 }
15}
16
17pub fn sing(start: u32, end: u32) -> String {
18 // Note: call to `join` can be substituted with `.intersperse(String::from("\n")).collect()`
19 (end..=start).rev().map(|x| verse(x)).join("\n")
20}