Last active
July 19, 2018 19:54
-
-
Save peregrinogris/aa0a286d86e1c705d3890a28d47b837b to your computer and use it in GitHub Desktop.
Twelve Days of Christmas implementation in Rust.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let gifts = [ | |
("First", "a Partridge in a Pear Tree"), | |
("Second", "Two Turtle Doves"), | |
("Third", "Three French Hens"), | |
("Fourth", "Four Calling Birds"), | |
("Fifth", "Five Gold Rings"), | |
("Sixth", "Six Geese a-Laying"), | |
("Seventh", "Seven Swans a-Swimming"), | |
("Eighth", "Eight Maids a-Milking"), | |
("Nineth", "Nine Ladies Dancing"), | |
("Tenth", "Ten Lords a-Leaping"), | |
("Eleventh", "Eleven Pipers Piping"), | |
("Twelfth", "Twelve Drummers Drumming"), | |
]; | |
for (day, (ordinal, _)) in gifts.iter().enumerate() { | |
println!("On the {} day of Christmas my true love sent to me", &ordinal); | |
for (_, (_, verse)) in gifts[1..day + 1].iter().rev().enumerate() { | |
println!("{},", verse); | |
} | |
println!("{}{}.\n", if day >= 1 {"and "} else {""}, gifts[0].1); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let gifts = [ | |
"a Partridge in a Pear Tree", | |
"Two Turtle Doves", | |
"Three French Hens", | |
"Four Calling Birds", | |
"Five Gold 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 days = [ | |
"First", | |
"Second", | |
"Third", | |
"Fourth", | |
"Fifth", | |
"Sixth", | |
"Seventh", | |
"Eighth", | |
"Nineth", | |
"Tenth", | |
"Eleventh", | |
"Twelfth" | |
]; | |
for (day, &ordinal) in days.iter().enumerate() { | |
println!("On the {} day of Christmas my true love sent to me", &ordinal); | |
for (_, &verse) in gifts[1..day + 1].iter().rev().enumerate() { | |
println!("{},", verse); | |
} | |
println!("{}{}.\n", if day >= 1 {"and "} else {""}, gifts[0]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment