Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JaseHadd/f257a05a0736ddac869751c50890c657 to your computer and use it in GitHub Desktop.
Save JaseHadd/f257a05a0736ddac869751c50890c657 to your computer and use it in GitHub Desktop.
let gifts = [ "partridge in a pear tree", "Two turtle doves", "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 nth = [ "first", "second", "third", "fourth", "fifth", "sixth",
"seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth" ]
func gifts(for day: Int) -> String {
var result = "On the \(nth[day-1]) day of Christmas, my true love sent to me:\n"
if day > 1 {
for again in 1...day-1 { // .
let n = day - again // __/ \__
result += gifts[n] // \ / / /
if n > 1 { result += "," } // /.'o'.\ /| /| _ _ _
result += "\n" // .o.'. / |/ | (/_/ (_/ (_(_/
} // .'.'o'. `-' `-' ,- /
result += "And a " // o'.o.'.o. _/,' /) _/_
} else { // .'.o.'.'.o. / /_ _ . _ / _ _ __ _
result += "A " // .o.'.o.'.o.'. ( / (_/ (_(_/ )_(_/ / /_(_(_/_)
} // [_____] `-'
return result + gifts[0] + ".\n" // \___/
}
for day in 1...12 {
print(gifts(for: day))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment