Exemplo n.º 1
0
            public bool Match(Sue sueToMatch)
            {
                int correct = 0;
                if (Cats.HasValue && Cats.Value > sueToMatch.Cats.Value)
                    correct++;

                if (Samoyeds.HasValue && Samoyeds.Value == sueToMatch.Samoyeds.Value)
                    correct++;

                if (Pomeranians.HasValue && Pomeranians.Value < sueToMatch.Pomeranians.Value)
                    correct++;

                if (Akitas.HasValue && Akitas.Value == sueToMatch.Akitas.Value)
                    correct++;

                if (Vizslas.HasValue && Vizslas.Value == sueToMatch.Vizslas.Value)
                    correct++;

                if (Goldfish.HasValue && Goldfish.Value < sueToMatch.Goldfish.Value)
                    correct++;

                if (Trees.HasValue && Trees.Value > sueToMatch.Trees.Value)
                    correct++;

                if (Cars.HasValue && Cars.Value == sueToMatch.Cars.Value)
                    correct++;
                if (Perfumes.HasValue && Perfumes.Value == sueToMatch.Perfumes.Value)
                    correct++;
                if (Children.HasValue && Children.Value == sueToMatch.Children.Value)
                    correct++;
                return correct == 3;
            }
Exemplo n.º 2
0
 public void Main(string[] args)
 {
     var now = DateTime.Now;
     var sueToMatch = new Sue("Testsue: children: 3, cats: 7, samoyeds: 2, pomeranians: 3, akitas: 0, vizslas: 0, goldfish: 5, trees: 3, cars: 2, perfumes: 1");
     var input = File.ReadAllLines("input.txt").Select(x => new Sue(x)).Single(x => x.Match(sueToMatch));
     var time = DateTime.Now - now;
     Console.WriteLine(time.TotalMilliseconds);
     Console.ReadLine();
 }
Exemplo n.º 3
0
        public void Main(string[] args)
        {
            var now        = DateTime.Now;
            var sueToMatch = new Sue("Testsue: children: 3, cats: 7, samoyeds: 2, pomeranians: 3, akitas: 0, vizslas: 0, goldfish: 5, trees: 3, cars: 2, perfumes: 1");
            var input      = File.ReadAllLines("input.txt").Select(x => new Sue(x)).Single(x => x.Match(sueToMatch));
            var time       = DateTime.Now - now;

            Console.WriteLine(time.TotalMilliseconds);
            Console.ReadLine();
        }
Exemplo n.º 4
0
            public bool Match(Sue sueToMatch)
            {
                int correct = 0;

                if (Cats.HasValue && Cats.Value > sueToMatch.Cats.Value)
                {
                    correct++;
                }

                if (Samoyeds.HasValue && Samoyeds.Value == sueToMatch.Samoyeds.Value)
                {
                    correct++;
                }

                if (Pomeranians.HasValue && Pomeranians.Value < sueToMatch.Pomeranians.Value)
                {
                    correct++;
                }

                if (Akitas.HasValue && Akitas.Value == sueToMatch.Akitas.Value)
                {
                    correct++;
                }

                if (Vizslas.HasValue && Vizslas.Value == sueToMatch.Vizslas.Value)
                {
                    correct++;
                }

                if (Goldfish.HasValue && Goldfish.Value < sueToMatch.Goldfish.Value)
                {
                    correct++;
                }

                if (Trees.HasValue && Trees.Value > sueToMatch.Trees.Value)
                {
                    correct++;
                }

                if (Cars.HasValue && Cars.Value == sueToMatch.Cars.Value)
                {
                    correct++;
                }
                if (Perfumes.HasValue && Perfumes.Value == sueToMatch.Perfumes.Value)
                {
                    correct++;
                }
                if (Children.HasValue && Children.Value == sueToMatch.Children.Value)
                {
                    correct++;
                }
                return(correct == 3);
            }
Exemplo n.º 5
0
            static public Sue Parse(string input)
            {
                string[] split  = input.Split(" :,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                int[]    values = split.Where(s => { int v; return(int.TryParse(s, out v)); }).Select(int.Parse).ToArray();
                Sue      sue    = new Sue(values[0], new Dictionary <string, string>());

                for (int i = 0; i < split.Length - 1; i += 2)
                {
                    sue.Attributes[split[i]] = split[i + 1];
                }
                return(sue);
            }
Exemplo n.º 6
0
            static int Score(Sue sue)
            {
                var score = 0;

                foreach (var(name, value) in TargetProps)
                {
                    if (sue.Properties.TryGetValue(name, out var sueValue) && value == sueValue)
                    {
                        score++;
                    }
                }

                return(score);
            }
Exemplo n.º 7
0
        public void Should_Parse_Line_Into_Sue()
        {
            var line = "Sue 1: children: 1, cars: 8, vizslas: 7";

            var expected = new Sue(1, new Dictionary <string, int>()
            {
                { "children", 1 },
                { "cars", 8 },
                { "vizslas", 7 }
            });
            var result = Sue.FromString(line);

            Assert.Equal(expected.Id, result.Id);
            Assert.Equal(expected.Items.Count, result.Items.Count);
            Assert.Equal(expected.Items.Keys, result.Items.Keys);
            Assert.Equal(expected.Items.Values, result.Items.Values);
        }
Exemplo n.º 8
0
        public Challenge()
        {
            foreach (string data in inputList)
            {
                Sue sue        = new Sue();
                int splitIndex = data.IndexOf(':');
                foreach (string prop in data.Substring(splitIndex + 1).Split(','))
                {
                    string[] parts = prop.Split(':');
                    sue.properties[parts[0].Trim()] = int.Parse(parts[1].Trim());
                }
                _sues.Add(sue);
            }

            foreach (string prop in LoadFileLines("properties.txt"))
            {
                string[] parts = prop.Split(':');
                _knownProps[parts[0].Trim()] = int.Parse(parts[1].Trim());
            }
        }
Exemplo n.º 9
0
 private static bool CheckParam(Sue sue, KeyValuePair<string, int> patternParam, List<string> graterParamNames,
     List<string> fewerParamNames)
 {
     var patternParamName = patternParam.Key;
     if (!sue.Params.ContainsKey(patternParamName))
     {
         return true;
     }
     var paramValue = sue.Params[patternParamName];
     var patternParamValue = patternParam.Value;
     if (graterParamNames.Contains(patternParamName) && paramValue > patternParamValue)
     {
         return true;
     }
     if (fewerParamNames.Contains(patternParamName) && paramValue < patternParamValue)
     {
         return true;
     }
     return (paramValue == patternParamValue);
 }
Exemplo n.º 10
0
 private static List<Sue> ParseSues(string[] lines)
 {
     var regex = new Regex(@"^Sue (?<number>\d+): (?:(?<param>\w+): (?<value>\d+)(?:, )?)+");
     var sues = new List<Sue>();
     foreach (var line in lines)
     {
         var match = regex.Match(line);
         var number = int.Parse(match.Groups["number"].Value);
         var paramCaptures = match.Groups["param"].Captures;
         var valueCaptures = match.Groups["value"].Captures;
         var sue = new Sue(number);
         for (int i = 0; i < paramCaptures.Count; i++)
         {
             var paramName = paramCaptures[i].Value;
             var paramValue = int.Parse(valueCaptures[i].Value);
             sue.Params.Add(paramName, paramValue);
         }
         sues.Add(sue);
     }
     return sues;
 }
Exemplo n.º 11
0
        public Day16() : base(16, 2015, "")
        {
            List <Sue> aunts = new List <Sue>();

            int id = 1;

            foreach (string line in Input.SplitByNewline())
            {
                Sue newSue = new Sue(line, id);
                if (newSue.FactsMatchOne(3, 7, 2, 3, 0, 0, 5, 3, 2, 1))
                {
                    partOne = id;
                }
                if (newSue.FactsMatchTwo(3, 7, 2, 3, 0, 0, 5, 3, 2, 1))
                {
                    partTwo = id;
                }

                aunts.Add(new Sue(line, id));
                id++;
            }
        }