summaryrefslogtreecommitdiffstats
path: root/src/christmas_song
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/christmas_song/Cargo.toml6
-rw-r--r--src/christmas_song/src/main.rs59
2 files changed, 65 insertions, 0 deletions
diff --git a/src/christmas_song/Cargo.toml b/src/christmas_song/Cargo.toml
new file mode 100644
index 0000000..25474b6
--- /dev/null
+++ b/src/christmas_song/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "christmas_song"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
diff --git a/src/christmas_song/src/main.rs b/src/christmas_song/src/main.rs
new file mode 100644
index 0000000..b04524d
--- /dev/null
+++ b/src/christmas_song/src/main.rs
@@ -0,0 +1,59 @@
+fn main() {
+ const DAYS_AND_GIFTS: [[&str; 3]; 12] = [
+ ["first", "a", "brand new SCV"],
+ ["second", "two", "Terran Wraiths"],
+ ["third", "three", "Marines"],
+ ["fourth", "four", "Hydralisks"],
+ ["fifth", "five", "newborn Queens"],
+ ["sixth", "six", "Zealots fighting"],
+ ["seventh", "seven", "Zerglings swarming"],
+ ["eighth", "eight", "Archons burning"],
+ ["ninth", "nine", "Battlecruisers"],
+ ["tenth", "ten", "Ultralisks"],
+ ["eleventh", "eleven", "Science Vessels"],
+ ["twelfth", "twelve", "Arbiters"],
+ ];
+
+ for i in 0..12 {
+ println!("On the {} day of Christmas, Blizzard gave to me:",
+ DAYS_AND_GIFTS[i][0]);
+
+ let mut gifts = String::new();
+
+ for j in 0..=i {
+ gifts = match j {
+ 0 => format!("{} {}.\n",
+ DAYS_AND_GIFTS[j][1],
+ DAYS_AND_GIFTS[j][2],),
+ 1 => format!("{} {} and {gifts}",
+ DAYS_AND_GIFTS[j][1],
+ DAYS_AND_GIFTS[j][2]),
+ _ => format!("{}, {gifts}",
+ match i {
+ 8 if j == 7 => "power overwhelming".to_string(),
+ 9 if j == 7 => "terror all-consuming".to_string(),
+ 10 if j == 7 => "I hate all this singing".to_string(),
+ _ => format!("{} {}",
+ DAYS_AND_GIFTS[j][1],
+ DAYS_AND_GIFTS[j][2]),
+ }
+ )
+ }
+ }
+
+ println!("{}", capitalize(&gifts));
+ }
+
+ println!("Why am I so jolly?\n");
+ println!("Hey! Who spiked the egg nog?");
+}
+
+fn capitalize(s: &str) -> String {
+ let mut chars = s.chars();
+
+ match chars.next() {
+ Some(first) => first.to_uppercase().collect::<String>()
+ + chars.as_str(),
+ None => String::new(),
+ }
+}