2019-02-06 11:52:08 -05:00
|
|
|
const ORDINALS: [&str; 12] = [
|
2019-02-06 12:07:08 -05:00
|
|
|
"first", "second", "third", "fourth", "fifth", "sixth",
|
|
|
|
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth",
|
2019-02-06 11:52:08 -05:00
|
|
|
];
|
|
|
|
|
|
|
|
const GIFTS: [&str; 12] = [
|
|
|
|
"Twelve drummers drumming",
|
|
|
|
"Eleven pipers piping",
|
|
|
|
"Ten lords a-leaping",
|
|
|
|
"Nine ladies dancing",
|
|
|
|
"Eight maids a-milking",
|
|
|
|
"Seven swans a-swimming",
|
|
|
|
"Six geese a-laying",
|
|
|
|
"Five golden rings",
|
|
|
|
"Four calling birds",
|
|
|
|
"Three french hens",
|
|
|
|
"Two turtle doves",
|
|
|
|
"and a partridge in a pear tree.",
|
|
|
|
];
|
|
|
|
|
2019-02-06 12:07:08 -05:00
|
|
|
fn get_gifts(n: usize) -> String {
|
|
|
|
match n {
|
|
|
|
0 => String::from("A partridge in a pear tree."),
|
|
|
|
_ => {
|
|
|
|
// The highest index is 11, and we want
|
|
|
|
// the highest index to start, so we can
|
|
|
|
// easily have the cumulative list each verse.
|
|
|
|
let gift_index = 11 - n;
|
|
|
|
|
|
|
|
// Get the slice of the array of gifts, from
|
|
|
|
// the index to the end of the array
|
|
|
|
GIFTS[gift_index..]
|
|
|
|
.to_vec() // So we have the join method that returns a string
|
|
|
|
.join(",\n")
|
|
|
|
}
|
|
|
|
}
|
2019-02-06 11:52:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
for n in 0..12 {
|
2019-02-06 12:07:08 -05:00
|
|
|
println!(
|
|
|
|
"On the {} day of Christmas, my true love gave to me: \n{}\n",
|
|
|
|
ORDINALS[n],
|
|
|
|
get_gifts(n)
|
|
|
|
);
|
2019-02-06 11:52:08 -05:00
|
|
|
}
|
|
|
|
}
|