Last active
December 20, 2016 05:24
-
-
Save daltonclaybrook/717cc4edb13b0a2fbb2416f91b489eaf to your computer and use it in GitHub Desktop.
This file contains 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
//: Playground - noun: a place where people can play | |
import UIKit | |
func wordFromNum(_ num: Int) -> String { | |
let suffixes = ["th","st","nd","rd","th"] | |
var idx = min(num % 10, suffixes.count-1) | |
let tens = num % 100 | |
if tens > 10 && tens < 14 { | |
idx = 0 | |
} | |
return "\(num)\(suffixes[idx])" | |
} | |
let phrases = [ | |
"a Partridge in a Pear Tree", | |
"2 Turtle Doves", | |
"3 French Hens", | |
"4 Calling Birds", | |
"** FIIIIIVE GOOOOLDEN RIIIIIIIINGS! **", | |
"6 Geese a Laying", | |
"7 Swans a Swimming", | |
"8 Maids a Milking", | |
"9 Ladies Dancing", | |
"10 Lords a Leaping", | |
"11 Pipers Piping", | |
"12 Drummers Drumming" | |
] | |
for idx in (0...11) { | |
var verse = "On the \(wordFromNum(idx+1)) day of Christmas\nmy true love sent to me:\n" | |
for reversedIdx in (0...idx).reversed() { | |
if reversedIdx == 0 && idx > 0 { | |
verse += "and " | |
} | |
verse += phrases[reversedIdx] + "\n" | |
} | |
print("\(verse)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment