clippy issues
This commit is contained in:
parent
5351c69993
commit
9ee73c9129
1 changed files with 16 additions and 9 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
pub fn recite(start_bottles: u32, take_down: u32) -> String {
|
pub fn recite(start_bottles: u32, take_down: u32) -> String {
|
||||||
let end_bottles = start_bottles - take_down;
|
let end_bottles = start_bottles - take_down;
|
||||||
|
|
||||||
((end_bottles + 1)..=start_bottles)
|
((end_bottles + 1)..=start_bottles)
|
||||||
.rev()
|
.rev()
|
||||||
.map(|n| verse(n))
|
.map(verse)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("\n\n")
|
.join("\n\n")
|
||||||
}
|
}
|
||||||
|
|
@ -13,22 +13,29 @@ fn verse(n: u32) -> String {
|
||||||
let next_bottle = bottle_str(n - 1).to_lowercase();
|
let next_bottle = bottle_str(n - 1).to_lowercase();
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{0} hanging on the wall,\n\
|
"{current_bottle} hanging on the wall,\n\
|
||||||
{0} hanging on the wall,\n\
|
{current_bottle} hanging on the wall,\n\
|
||||||
And if one green bottle should accidentally fall,\n\
|
And if one green bottle should accidentally fall,\n\
|
||||||
There'll be {1} hanging on the wall.",
|
There'll be {next_bottle} hanging on the wall.",
|
||||||
current_bottle, next_bottle
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bottle_str(n: u32) -> String {
|
fn bottle_str(n: u32) -> String {
|
||||||
let count_str = match n {
|
let count_str = match n {
|
||||||
10 => "Ten", 9 => "Nine", 8 => "Eight", 7 => "Seven", 6 => "Six",
|
10 => "Ten",
|
||||||
5 => "Five", 4 => "Four", 3 => "Three", 2 => "Two", 1 => "One",
|
9 => "Nine",
|
||||||
|
8 => "Eight",
|
||||||
|
7 => "Seven",
|
||||||
|
6 => "Six",
|
||||||
|
5 => "Five",
|
||||||
|
4 => "Four",
|
||||||
|
3 => "Three",
|
||||||
|
2 => "Two",
|
||||||
|
1 => "One",
|
||||||
_ => "No",
|
_ => "No",
|
||||||
};
|
};
|
||||||
|
|
||||||
let plural = if n == 1 { "bottle" } else { "bottles" };
|
let plural = if n == 1 { "bottle" } else { "bottles" };
|
||||||
|
|
||||||
format!("{count_str} green {plural}")
|
format!("{count_str} green {plural}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue