// .\bin\netcoreapp3.1\AdventOfCode2020.exe "Inputs" 1 1
        private static void Main(string[] args)
        {
            Helper.Logger = new ConsoleLogger();

            try
            {
                if (args.Length < 3)
                {
                    throw new Exception("Did not get expected number of params, which is 3");
                }

                if (!int.TryParse(args[1], out int dayNo))
                {
                    throw new Exception("Param 1 is day number, should be int");
                }

                if (!int.TryParse(args[2], out int puzzleNo))
                {
                    throw new Exception("Param 2 is puzzle number, should be int");
                }

                IDay day    = InstantiateDay(dayNo);
                var  inputs = Helper.GetInputs(args[0], day.InputFiles);
                SolvePuzzle(puzzleNo, day, inputs);
            }
            catch (Exception e)
            {
                Helper.Logger.Log(e);
            }
        }
        public Day09Tests()
        {
            _input = new List <string>
            {
                "35",
                "20",
                "15",
                "25",
                "47",
                "40",
                "62",
                "55",
                "65",
                "95",
                "102",
                "117",
                "150",
                "182",
                "127",
                "219",
                "299",
                "277",
                "309",
                "576",
            };

            _day = new Day09(5);
        }
Exemple #3
0
        private void ExecuteDay(int day)
        {
            EnsureData((int)day);
            Type dayType = Type.GetType($"AOC2019.Day{day}");
            IDay dayObj  = (IDay)Activator.CreateInstance(dayType);

            Console.WriteLine($" -* Day {day} *-");


            Stopwatch t = new Stopwatch();

            t.Start();
            var x = dayObj.SolvePartOne();

            t.Stop();
            var t1 = t.Elapsed.ToString("g");

            t.Reset();
            Console.WriteLine($"Part 1: {x}");
            Console.WriteLine($"Time taken for part 1: {t1}");

            t.Start();
            var y = dayObj.SolvePartTwo();

            t.Stop();
            var t2 = t.Elapsed.ToString("g");

            Console.WriteLine($"Part 2: {y}");
            Console.WriteLine($"Time taken for part 2: {t2}");

            Console.WriteLine($"---------------------------");
        }
Exemple #4
0
        static void Main(string[] args)
        {
            Boolean.TryParse(args[0], out bool isTest);
            int day;

            do
            {
                Console.WriteLine("Which day would you like to test?\n");
                bool parsed = int.TryParse(Console.ReadLine(), out day);
                if (!parsed || day < 1 || day > 25)
                {
                    Console.WriteLine("Incorrect day. Insert a day between 1 and 25 inclusive.");
                }
                else
                {
                    break;
                }
            } while (true);

            IDay solution = solutions[day - 1];

            string[] inputs = isTest ? GetTestInputs(day) : GetInputs(day);
            Console.WriteLine($"Press any key to test day {day} part 1...");
            Console.ReadKey(true);
            Console.WriteLine($"Testing Part 1 of day {day}");
            solution.DoPart1(inputs);
            Console.WriteLine($"Press any key to test day {day} part 2...");
            Console.ReadKey(true);
            Console.WriteLine($"Testing Part 2 of day {day}");
            solution.DoPart2(inputs);
        }
Exemple #5
0
        static void Main()
        {
            List <Type> days = Assembly.GetExecutingAssembly().GetTypes().Where(t => Regex.IsMatch(t.Name, "^Day[0-9]+$")).OrderBy(t => t.Name).ToList();

            foreach (var dayType in days)
            {
                IDay day = (IDay)Activator.CreateInstance(dayType);
                if (!day.IsImplemented)
                {
                    continue;
                }

                Console.WriteLine($"***** {dayType.Name} *****");
                if (day.IsAssignment1Complete)
                {
                    Console.WriteLine(day.GetAssignment1());
                }

                if (day.IsAssignment2Complete)
                {
                    Console.WriteLine(day.GetAssignment2());
                }

                Console.WriteLine();
            }

            Console.ReadKey();
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            ServiceCollection collection = new();

            // Discover all day instances, and add them to our collection
            foreach (Type dayType in typeof(Program).Assembly.GetTypes().Where(t => t.IsAssignableTo(typeof(IDay)) && !t.IsAbstract))
            {
                collection.AddTransient(typeof(IDay), dayType);
            }

            using ServiceProvider provider = collection.BuildServiceProvider();

            IEnumerable <IDay> days = provider.GetServices <IDay>().OrderByDescending(d => d.Year).ThenByDescending(d => d.Number);

            if (args.Length >= 1)
            {
                days = days.Where(d => d.Year == int.Parse(args[0]));
                if (args.Length >= 2)
                {
                    days = days.Where(d => d.Number == int.Parse(args[1]));
                }
            }

            IDay day = days.First();

            Console.WriteLine($"Day {day.Year}-{day.Number:D2}:");
            Console.WriteLine($"Part 1 answer: {day.Part1()}");
            Console.WriteLine($"Part 2 answer: {day.Part2()}");
        }
        public void SetStateForSlot(IDay day,
                                    EntityState modified)
        {
            Day instance = ConvertToDay(day);

            Entry(instance).State = EntityState.Modified;
        }
Exemple #8
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Du mangler dag!");
                return;
            }
            int dayNumber = 0;

            try {
                dayNumber = Int32.Parse(args[0]);
            } catch {
                Console.WriteLine("Ugyldig dag " + args[0]);
                return;
            }

            IDay day = (IDay)Activator.CreateInstance(Type.GetType($"AOC2020.Day{dayNumber}, 2020"));

            Console.WriteLine("Starting");

            Stopwatch sw = Stopwatch.StartNew();

            if (args.Length > 1 && args[1] == "test")
            {
                day.Test();
            }
            else
            {
                day.Run();
            }

            Console.WriteLine($"Done in {sw.ElapsedMilliseconds} ms");
        }
Exemple #9
0
        public void SetStateForSlot(IDay day,
                                    EntityState modified)
        {
            Day instance = ConvertToDay(day);

            Entry(instance).State = EntityState.Modified;
        }
Exemple #10
0
        public bool AddDay(IDay day)
        {
            try
            {
                RemoveOldEntryIfTheSameDay();

                bool success   = false;
                int  beforeAdd = _days.Count;
                _days.Add(day);

                JsonData.SaveDaysToJson(_days);
                if (beforeAdd < _days.Count)
                {
                    success = true;
                }
                return(success);
            }
            catch
            {
                System.Console.WriteLine("An error occurred while trying to Add Day. \n" +
                                         "Program will now crash... \n");

                // BUG: application crashes if moodStats.json has not been created. (should be fixed now, but leaving it here for now.)
                System.Console.WriteLine();
                Thread.Sleep(5000);
                throw;
            }
        }
Exemple #11
0
 public Time(IClock clock, IDay day, decimal month, IYear year)
 {
     this.clock = clock;
     this.day   = day;
     this.month = month;
     this.year  = year;
 }
Exemple #12
0
        static void Main()
        {
            HiPerfTimer timer = new HiPerfTimer();

            foreach (Type day in Assembly.GetEntryAssembly().GetTypes()
                     .Where(x => x.IsInterface is false && typeof(IDay).IsAssignableFrom(x) && !x.Name.EndsWith("99") && x.Namespace.Contains("2021"))
                     .OrderByDescending(x => int.Parse(x.Name.Replace("Day", string.Empty))))
            {
                Console.WriteLine("=======================================");
                Console.WriteLine(day.Namespace + "." + day.Name);
                Console.WriteLine("=======================================");

                IDay puzzle = (IDay)Activator.CreateInstance(day);

                // Solve part 1
                string puzzleInput = "0";
                using (var webClient = new WebClient())
                {
                    webClient.Headers.Add(HttpRequestHeader.Cookie, "session=" + Environment.GetEnvironmentVariable("AoC-Session"));
                    var puzzleDay = day.Name.Replace("Day", string.Empty);
                    try
                    {
                        puzzleInput = webClient.DownloadString($"https://adventofcode.com/2021/day/{puzzleDay}/input");
                        puzzleInput = puzzleInput.Trim(' ', '\r', '\n');
                    }
                    catch
                    {
                        Console.WriteLine("Could not find puzzle input for " + day.Name);
                    }
                }

                Console.WriteLine("Example : " + puzzle.SolvePart1(puzzle.ExampleInput));
                timer.Start();
                long solutionPart1 = puzzle.SolvePart1(puzzleInput);
                timer.Stop();
                if (solutionPart1 > 0)
                {
                    TextCopy.ClipboardService.SetText(solutionPart1.ToString());
                }
                Console.WriteLine("Solution: " + solutionPart1);
                Console.WriteLine("Duration: " + timer.DurationFormatted);
                Console.WriteLine();

                Console.WriteLine("Example : " + puzzle.SolvePart2(puzzle.ExampleInput));
                timer.Start();
                long solutionPart2 = puzzle.SolvePart2(puzzleInput);
                timer.Stop();
                if (solutionPart2 > 0)
                {
                    TextCopy.ClipboardService.SetText(solutionPart2.ToString());
                }
                Console.WriteLine("Solution: " + solutionPart2);
                Console.WriteLine("Duration: " + timer.DurationFormatted);
                Console.WriteLine();

                Console.ReadKey();
                Console.WriteLine();
            }
        }
        public void Constructor_February2019_FirstDayInFebruaryIsFriday()
        {
            AttendanceListData listData = GetAttendanceListData();

            IDay firstDay = listData.Days.FirstOrDefault();

            Assert.That(firstDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Friday));
        }
Exemple #14
0
 public static void ValidateOrExit(IDay daytoPlay)
 {
     if (daytoPlay == null)
     {
         Console.WriteLine("The class for the Day you are trying to play does not exist.");
         Environment.Exit(1002);
     }
 }
Exemple #15
0
        public IDayForResponse Save(IDayForResponse day)
        {
            IDay toBeUpdated = ToDay(day);

            m_Repository.Save(toBeUpdated);

            return(new DayForResponse(toBeUpdated));
        }
        public void Constructor_February2019_LastDayInFebruaryIsThursday()
        {
            AttendanceListData listData = GetAttendanceListData();

            IDay lastDay = listData.Days.LastOrDefault();

            Assert.That(lastDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Thursday));
        }
Exemple #17
0
 public OYSTimeSpan(IYear Y, IMonth M, IWeek W, IDay D, IHour h, IMinute m, ISecond s)
 {
     this.Years   = Y;
     this.Months  = M;
     this.Days    = D;
     this.Hours   = h;
     this.Minutes = m;
     this.Seconds = s;
 }
Exemple #18
0
        public static void Run(IDay day)
        {
            var name = day.GetType().ToString();

            Console.WriteLine($"===================={name}====================");
            Console.WriteLine($"Part1: {day.Part1()}");
            Console.WriteLine($"Part2: {day.Part2()}");
            Console.WriteLine("==================================================");
        }
Exemple #19
0
 public DayPresenter(
     IDayOutputPort dayOutputPort,
     IDay day,
     SignalBus signalBus)
 {
     _dayOutputPort = dayOutputPort;
     _day           = day;
     _signalBus     = signalBus;
 }
 public DayTest()
 {
     this.date  = new DateTime(YEAR, 3, 26);
     this.date2 = new DateTime(YEAR, 4, 10);
     this.date3 = new DateTime(YEAR, 2, 14);
     day        = new Day(date);
     day2       = new Day(date2);
     day3       = new Day(date3);
 }
Exemple #21
0
            public OYSDate(string date)
            {
                OYSDate conversion;

                TryParse(date, out conversion);
                this.Year  = conversion.Year;
                this.Month = conversion.Month;
                this.Day   = conversion.Day;
            }
        public void Constructor_June2019_FourteenthDayIsNotAHoliday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2019);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.January, 2019);
            IDay day = listData.Days[13];

            Assert.That(day.Holiday, Is.EqualTo(Holiday.None));
        }
        public void Constructor_February2020LeapYear_FirstDayIsSaturday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2020);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.February, 2020);
            IDay firstDay = listData.Days.FirstOrDefault();

            Assert.That(firstDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Saturday));
        }
        public void Constructor_August2024_LastDayIsSaturday()
        {
            IDaysOffData daysOff = Mock.Of <IDaysOffData>(d => d.Year == 2024);

            AttendanceListData listData = new AttendanceListData(daysOff, GetListOfPeople(), Month.August, 2024);
            IDay lastDay = listData.Days.LastOrDefault();

            Assert.That(lastDay.DayOfWeek, Is.Not.Null.And.EqualTo(DayOfWeek.Saturday));
        }
Exemple #25
0
 public Slot()
 {
     WeekNumber = new WeekNumber(new List <int>());
     UID        = _nextUid++;
     IsSelected = false;
     StartTime  = Time.CreateTime_24HourFormat(0, 0);
     EndTime    = Time.CreateTime_24HourFormat(0, 0);
     _day       = Day.Unassigned;
 }
 public OYSDateTime(IYear YYYY, IMonth MM, IDay DD, IHour hh, IMinute mm, ISecond ss)
 {
     this.Year   = YYYY;
     this.Month  = MM;
     this.Day    = DD;
     this.Hour   = hh;
     this.Minute = mm;
     this.Second = ss;
 }
Exemple #27
0
        public async Task Run()
        {
            string[] input = (await IDay.ReadInputLinesAsync(23));

            LinkedList <int> cups  = new LinkedList <int>();
            LinkedList <int> cups2 = new LinkedList <int>();

            Dictionary <int, LinkedListNode <int> > nodeLoc  = new Dictionary <int, LinkedListNode <int> >();
            Dictionary <int, LinkedListNode <int> > nodeLoc2 = new Dictionary <int, LinkedListNode <int> >();

            Dictionary <int, bool> isIn  = new Dictionary <int, bool>();
            Dictionary <int, bool> isIn2 = new Dictionary <int, bool>();

            for (int i = 0; i < input[0].Length; i++)
            {
                int num = int.Parse(input[0][i].ToString());
                nodeLoc[num]  = cups.AddLast(num);
                nodeLoc2[num] = cups2.AddLast(num);
                isIn[num]     = true;
                isIn2[num]    = true;
            }

            int moreCup = cups.Max() + 1;

            while (moreCup <= 1000000)
            {
                nodeLoc2[moreCup] = cups2.AddLast(moreCup);
                isIn2[moreCup]    = true;
                moreCup++;
            }

            ShuffleCups(cups, nodeLoc, isIn, 100);

            LinkedListNode <int> index = nodeLoc[1];

            for (int i = 1; i < cups.Count; i++)
            {
                index        = index.Next ?? cups.First;
                Part1Answer += index.Value;
            }

            ShuffleCups(cups2, nodeLoc2, isIn2, 10000000);

            index = nodeLoc2[1];

            long product = 1;

            for (int i = 0; i < 2; i++)
            {
                index = index.Next ?? cups.First;
                Log.Verbose(index.Value.ToString());
                product *= index.Value;
            }

            Part2Answer = product.ToString();
        }
Exemple #28
0
        // todo do the delete below for all other finders
        public IDayForResponse Delete(int id)
        {
            IDay day = m_Repository.FindById(id);

            m_Repository.Remove(day);

            return(day == null
                       ? null
                       : new DayForResponse(day));
        }
Exemple #29
0
        private static void RunDay(IDay day, string input)
        {
            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part1)}");
            day.Part1(input);
            Console.WriteLine();

            Console.WriteLine($"{day.GetType().Name}, {nameof(IDay.Part2)}");
            day.Part2(input);
            Console.WriteLine();
        }
        public Day13Tests()
        {
            _input = new List <string>
            {
                "939",
                "7,13,x,x,59,x,31,19",
            };

            _day = new Day13(1068781);
        }
Exemple #31
0
        public async Task Run()
        {
            string[] input = await IDay.ReadInputLinesAsync(25);

            long cardPK = long.Parse(input[0]), doorPK = long.Parse(input[1]);
            long cardLoop = GetLoopVal(cardPK), doorLoop = GetLoopVal(doorPK);
            long cardEncryptionKey = GetKey(doorPK, cardLoop), doorEncryptionKey = GetKey(cardPK, doorLoop);

            Part1Answer = cardEncryptionKey.ToString();
        }
        private Day ConvertToDay(IDay day)
        {
            var instance = day as Day;

            if ( instance == null )
            {
                throw new ArgumentException("Provided 'day' instance is not a Day!",
                                            "day");
            }

            Doctor doctor = DbSetDoctors.Find(day.DoctorId);

            instance.Doctor = doctor;

            return instance;
        }
        public void Add(IDay doctor)
        {
            Day instance = ConvertToDay(doctor);

            DbSetDays.Add(instance);
        }
        public void Remove(IDay day)
        {
            Day instance = ConvertToDay(day);

            DbSetDays.Remove(instance);
        }