Skip to content

Instantly share code, notes, and snippets.

@zntfdr
Last active January 18, 2017 21:09
Show Gist options
  • Save zntfdr/237f393d241d1126c1ce3190f1dce690 to your computer and use it in GitHub Desktop.
Save zntfdr/237f393d241d1126c1ce3190f1dce690 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))
}
@zntfdr
Copy link
Author

zntfdr commented Dec 16, 2016

@patrickkim : fixed, thanks!

@bottomoftheheap9000: immensely haha

@JaseHadd
Copy link

This is nitpicky, but there are two extra spaces on line 2 before "Six geese...."

@zntfdr
Copy link
Author

zntfdr commented Dec 16, 2016

@jasef: they were there because I've added en in golden rings a few hours ago, thanks for noticing! (fixed)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment