Last active
December 22, 2015 05:54
-
-
Save endurance/ade7b92c760d6535d9d2 to your computer and use it in GitHub Desktop.
Boon Group Twelve Days of Christmas
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
using System; | |
using System.Threading.Tasks; | |
namespace TweleveDaysOfChristmas | |
{ | |
internal class Program | |
{ | |
public static string[] SpokenNumber = | |
{ | |
"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", | |
"Eigth", "Nineth", "Tenth", "Eleventh", "Twelveth" | |
}; | |
public static string[] Gifts = | |
{ | |
"A 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" | |
}; | |
private static void Main() | |
{ | |
var giftString = string.Empty; | |
for (var i = 0; i < Gifts.Length; i++) | |
{ | |
string dayString; | |
CreateTheStrings(i, out dayString, ref giftString); | |
Console.WriteLine($"On the {dayString} Day of Christmas \n My true love gave to me: \n{giftString}"); | |
Task.Delay(2000).Wait(); | |
} | |
Console.ReadKey(); | |
} | |
private static void CreateTheStrings(int maxIndex, out string day, ref string giftString) | |
{ | |
day = SpokenNumber[maxIndex]; | |
if (maxIndex == 1) giftString = giftString.Insert(0, " and "); | |
giftString = giftString.Insert(0, Gifts[maxIndex] + "\n"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, the previous solution, it isnt really O(n^2) i would say. Since you don't fully go through the second array, it's most likely closer to O(NLogN) than it would be O(N^2)