Created
December 16, 2015 14:32
-
-
Save johnboker/0c9496dd76444f72e8aa 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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
namespace AdventOfCodeDay16 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var ss = new StreamReader("../../input1.txt"); | |
string line; | |
var input = new List<string>(); | |
var sues = new List<Sue>(); | |
while ((line = ss.ReadLine()) != null) | |
{ | |
input.Add(line); | |
var nameEndsAt = line.IndexOf(':'); | |
var name = line.Substring(0, nameEndsAt); | |
var sue = new Sue | |
{ | |
Name = name | |
}; | |
var parts = line.Substring(nameEndsAt + 2).Split(','); | |
foreach (var t in parts) | |
{ | |
var item = t.Trim().Split(':'); | |
var value = int.Parse(item[1].Trim()); | |
switch (item[0]) | |
{ | |
case "children": | |
sue.Children = value; | |
break; | |
case "cats": | |
sue.Cats = value; | |
break; | |
case "samoyeds": | |
sue.Samoyeds = value; | |
break; | |
case "pomeranians": | |
sue.Pomeranians = value; | |
break; | |
case "akitas": | |
sue.Akitas = value; | |
break; | |
case "vizslas": | |
sue.Vizslas = value; | |
break; | |
case "goldfish": | |
sue.Goldfish = value; | |
break; | |
case "trees": | |
sue.Trees = value; | |
break; | |
case "cars": | |
sue.Cars = value; | |
break; | |
case "perfumes": | |
sue.Perfumes = value; | |
break; | |
} | |
} | |
sues.Add(sue); | |
} | |
// for part 1 change all < to = | |
var matches = sues.Where(a => | |
(a.Children == 3 || a.Children == null) && | |
(a.Cats > 7 || a.Cats == null) && | |
(a.Samoyeds == 2 || a.Samoyeds == null) && | |
(a.Pomeranians < 3 || a.Pomeranians == null) && | |
(a.Akitas == 0 || a.Akitas == null) && | |
(a.Vizslas == 0 || a.Vizslas == null) && | |
(a.Goldfish < 5 || a.Goldfish == null) && | |
(a.Trees > 3 || a.Trees == null) && | |
(a.Cars == 2 || a.Cars == null) && | |
(a.Perfumes == 1 || a.Perfumes == null)).ToList(); | |
foreach (var m in matches) | |
{ | |
Console.WriteLine(m.Name); | |
} | |
Console.ReadLine(); | |
} | |
} | |
public class Sue | |
{ | |
public string Name { get; set; } | |
public int? Children { get; set; } | |
public int? Cats { get; set; } | |
public int? Samoyeds { get; set; } | |
public int? Pomeranians { get; set; } | |
public int? Akitas { get; set; } | |
public int? Vizslas { get; set; } | |
public int? Goldfish { get; set; } | |
public int? Trees { get; set; } | |
public int? Cars { get; set; } | |
public int? Perfumes { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment