Skip to content

Instantly share code, notes, and snippets.

@200even
Last active August 29, 2015 14:24
Show Gist options
  • Save 200even/0f0cf303f2782125b5fc to your computer and use it in GitHub Desktop.
Save 200even/0f0cf303f2782125b5fc to your computer and use it in GitHub Desktop.
Scott - Week2.Day3 - Secret Santa
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Week2Day3_SecretSanta
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Secret Santa Picker\r\n");
Thread.Sleep(100);
List<Gifter> gifters = ParseData();
List<Gifter> recipients = new List<Gifter>(gifters);
recipients = recipients.OrderBy(x => Guid.NewGuid()).ToList();
//prevents last person from picking self
if (recipients.Last() == gifters.Last())
{
recipients.Reverse();
}
foreach (Gifter gifter in gifters)
{
if (gifter != recipients.First())
{
Console.WriteLine(gifter.firstName + " " + gifter.lastName + " is Secret Santa for " + recipients.First().firstName + " " + recipients.First().lastName);
recipients.Remove(recipients.First());
continue;
}
else
Console.WriteLine(gifter.firstName + " " + gifter.lastName + " is Secret Santa for " + recipients.Last().firstName + " " + recipients.Last().lastName);
recipients.Remove(recipients.Last());
}
Console.ReadLine();
}
private static List<Gifter> ParseData()
{
string[] fileContents = File.ReadAllLines(@"\\psf\Home\Documents\TIY\Secret_Santa.txt");
List<Gifter> gifters = new List<Gifter>();
foreach (string row in fileContents)
{
if (row.StartsWith("Name"))
{
continue;
}
string[] contactList = row.Split(' ');
Gifter gifter = new Gifter();
gifter.firstName = contactList[0];
gifter.lastName = contactList[1];
gifter.email = contactList[2];
gifters.Add(gifter);
}
return gifters;
}
public class Gifter
{
public string firstName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment