Table of content

What is this?

The rules of the game are explained in my original post.

I posting this a little late, and I’m posting a challange I’ve had up my sleeve. Keeping up the pace of daily challanges is not easy.

11th Challenge

Challenge

  • Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” taking advantage of the repetition in the song. - Offical Rust Documentation

Solution

	fn main() {

	    const PLACINGS:&[&str]=&["first","second","third","fourth","fifth","sixth","seventh","eigth","nineth","tenth","eleventh","twelth"];
	    const NUMBERS:&[&str]=&["One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve"];
	    const THINGS:&[&str]=&["Partridge in a pear tree ","Turtle doves ","French hens",
	                            "Collie birds","Golden rings","Geese a-laying","Swans a-swimming ","Maids a-milking",
	                            "Pipers piping ","Drummers drumming ","Lords a-leaping ","Ladies dancing "];

	   for num in 1..12{
	        println!("On the {} day of Christmas my true love gave to me",PLACINGS[num]);
	        for x in (1..(num)).rev() {
	            println!("{} {}",NUMBERS[x],THINGS[x]);
	        }

	        match num {
	            1 => print!("A "),
	            _ => print!("And a ")
	        }
	        println!("{}\n",THINGS[0]);
	   }
	}

	

See github and playground