From a881f5bca7e20890fda6440f28baf8cdde883db2 Mon Sep 17 00:00:00 2001 From: Bartal Laearsson Date: Fri, 2 Oct 2026 15:20:37 +0100 Subject: [PATCH] complete twelve days of christmas --- Cargo.lock | 4 +++ Cargo.toml | 2 +- .../Cargo.toml | 7 ++++++ .../src/main.rs | 25 +++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 common-programming-concepts-twelve-days-of-christmas/Cargo.toml create mode 100644 common-programming-concepts-twelve-days-of-christmas/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 7a3565b..07fef02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,6 +20,10 @@ version = "0.1.0" name = "common-programming-concepts-temp-converter" version = "0.1.0" +[[package]] +name = "common-programming-concepts-twelve-days-of-christmas" +version = "0.1.0" + [[package]] name = "getrandom" version = "0.2.17" diff --git a/Cargo.toml b/Cargo.toml index 2b32289..daab00e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [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" [workspace.package] diff --git a/common-programming-concepts-twelve-days-of-christmas/Cargo.toml b/common-programming-concepts-twelve-days-of-christmas/Cargo.toml new file mode 100644 index 0000000..25bc459 --- /dev/null +++ b/common-programming-concepts-twelve-days-of-christmas/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "common-programming-concepts-twelve-days-of-christmas" +edition.workspace = true +version.workspace = true +license.workspace = true + +[dependencies] diff --git a/common-programming-concepts-twelve-days-of-christmas/src/main.rs b/common-programming-concepts-twelve-days-of-christmas/src/main.rs new file mode 100644 index 0000000..4ca8cc0 --- /dev/null +++ b/common-programming-concepts-twelve-days-of-christmas/src/main.rs @@ -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]); + } + } +}