Skip to content

Instantly share code, notes, and snippets.

@endurance
Last active December 22, 2015 05:54
Show Gist options
  • Save endurance/ade7b92c760d6535d9d2 to your computer and use it in GitHub Desktop.
Save endurance/ade7b92c760d6535d9d2 to your computer and use it in GitHub Desktop.
Boon Group Twelve Days of Christmas
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");
}
}
}
@endurance
Copy link
Author

Yes I can :D

@endurance
Copy link
Author

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)

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