Skip to content

Commit a26f23e

Browse files
committed
complete the twelve-days mini project
1 parent 2593f85 commit a26f23e

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

projects/twelve-days/src/lyric.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub const LYRIC: [&str; 11] = [
2+
"Two turtle doves,",
3+
"Three French hens,",
4+
"Four calling birds,",
5+
"Five golden rings,",
6+
"Six geese a-laying,",
7+
"Seven swans a-swimming,",
8+
"Eight maids a-milking,",
9+
"Nine ladies dancing,",
10+
"Ten lords a-leaping,",
11+
"Eleven pipers piping,",
12+
"Twelve drummers drumming,",
13+
];

projects/twelve-days/src/main.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
mod lyric;
2+
3+
// ======================================================================
4+
15
fn main() {
2-
println!("Hello, world!");
6+
let mut lyric_lines: Vec<String> = Vec::new();
7+
8+
println!("{}", print_lyric(&lyric_lines));
9+
for section in lyric::LYRIC {
10+
lyric_lines.insert(0, section.to_string());
11+
println!("{}", print_lyric(&lyric_lines));
12+
}
13+
}
14+
15+
fn print_lyric(lyric_lines: &[String]) -> String {
16+
let lyric_text = lyric_lines.join("\n");
17+
return format!(
18+
"On the first day of Christmas,\nmy true love gave to me\n{lyric_text}\nA partridge in a pear tree.\n"
19+
);
320
}

0 commit comments

Comments
 (0)