complete twelve days of christmas

This commit is contained in:
2026-10-02 15:20:37 +01:00
parent 2aff2d45c1
commit a881f5bca7
4 changed files with 37 additions and 1 deletions
Generated
+4
View File
@@ -20,6 +20,10 @@ version = "0.1.0"
name = "common-programming-concepts-temp-converter" name = "common-programming-concepts-temp-converter"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "common-programming-concepts-twelve-days-of-christmas"
version = "0.1.0"
[[package]] [[package]]
name = "getrandom" name = "getrandom"
version = "0.2.17" version = "0.2.17"
+1 -1
View File
@@ -1,5 +1,5 @@
[workspace] [workspace]
members = ["common-programming-concepts", "common-programming-concepts-fibonacci", "common-programming-concepts-temp-converter","guessing-game"] members = ["common-programming-concepts", "common-programming-concepts-fibonacci", "common-programming-concepts-temp-converter", "common-programming-concepts-twelve-days-of-christmas","guessing-game"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
@@ -0,0 +1,7 @@
[package]
name = "common-programming-concepts-twelve-days-of-christmas"
edition.workspace = true
version.workspace = true
license.workspace = true
[dependencies]
@@ -0,0 +1,25 @@
fn main() {
let gifts: [&str;12] = ["A partridge in a pear tree", "Two turtle doves and", "Three french hens ",
"Four calling birds", "Five golden rings", "Six geese a-laying", "Seven swans a-swimming",
"Eight maids a-milking", "Nine ladies dancing", "Ten lords a-leaping",
"Eleven pipers piping", "Twelve drummers drumming" ];
let mut s = String::from(gifts[0]);
for day in 1..13 {
let ending = if day == 1 {
"st"
} else if day == 2 {
"nd"
} else {
"th"
};
println!("\nOn the {day}{ending} day of Christmas, my true love sent to me");
println!("{s}");
if day != 12 {
s.insert_str(0,"\n");
s.insert_str(0,gifts[day]);
}
}
}