示例#1
0
        /// <summary>
        ///     Initializes the loader using the default values.
        /// </summary>
        public Loader()
        {
            _containerLoader = this.CreateDefaultContainerLoader();

            // Load everything else into the container
            var hostAssembly = typeof(Loader).Assembly;

            QueuedActions.Add(container => container.LoadFrom(hostAssembly));

            // Make sure that the plugins are only added once
            if (!Plugins.HasElementWith(p => p is AutoPropertyInjector))
            {
                Plugins.Add(new AutoPropertyInjector());
            }

            if (!Plugins.HasElementWith(p => p is AutoMethodInjector))
            {
                Plugins.Add(new AutoMethodInjector());
            }

            if (!Plugins.HasElementWith(p => p is AutoFieldInjector))
            {
                Plugins.Add(new AutoFieldInjector());
            }

            // Add the initializer to the end of
            // the instantiation pipeline
            if (!Plugins.HasElementWith(p => p is InitializerPlugin))
            {
                Plugins.Add(new InitializerPlugin());
            }

            FileLoaders.Add(_containerLoader);
        }
示例#2
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            int inputWidth      = input[0].Length;
            int currentPosition = 3;

            input.RemoveAt(0); // skip the first

            long star1 = Solve(input, inputWidth, currentPosition, 1);

            List <int> star2inputRight = new List <int> {
                1, 3, 5, 7, 1
            };
            List <int> star2inputDown = new List <int> {
                1, 1, 1, 1, 2
            };

            var result = star2inputRight.Zip(star2inputDown, (r, d) => Solve(input, inputWidth, r, d));

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }

            long star2 = result.Aggregate((x, next) => x * next);


            Console.WriteLine("Star 1 {0}", star1);
            Console.WriteLine("Star 2 {0}", star2);
        }
示例#3
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            var countValid    = 0;
            var countValidTwo = 0;

            foreach (var item in input)
            {
                string[] components = item.Split(' ');
                int      minNumber  = Int32.Parse(components[0].Split('-')[0]);
                int      maxNumber  = Int32.Parse(components[0].Split('-')[1]);

                char letter = components[1].ToCharArray()[0];

                string password = components[2];

                int numTimes = countCharOccurrence(letter, password);
                // Console.WriteLine(numTimes);
                bool test = numTimes >= minNumber && numTimes <= maxNumber;
                if (test)
                {
                    countValid++;
                }

                if (starTwo(letter, password, minNumber, maxNumber))
                {
                    countValidTwo++;
                }
            }

            Console.WriteLine("Number of valid items for star 1 is {0}", countValid);
            Console.WriteLine("Number of valid items for star 2 is {0}", countValidTwo);
        }
示例#4
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            var set          = new HashSet <char>();
            var part1result  = new List <int>();
            var part2buffer  = new List <string>();
            int part2counter = 0;

            foreach (string line in input)
            {
                if (line.Trim().Length == 0)
                {
                    StoreResults(ref set, part1result, ref part2buffer, ref part2counter);
                }
                else
                {
                    part2buffer.Add(line);
                    foreach (char c in line)
                    {
                        set.Add(c);
                    }
                }
            }
            StoreResults(ref set, part1result, ref part2buffer, ref part2counter);

            var part1 = part1result.Aggregate((x, next) => x + next);

            Console.WriteLine("Part 1 result is {0}", part1);
            Console.WriteLine("Part 2 result is {0}", part2counter);
        }
示例#5
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            Solutions s = new Solutions(input);

            Console.WriteLine("day_09 output finished");
        }
示例#6
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            List <string> decodedLines  = new List <string>();
            string        currentString = "";

            foreach (string line in input)
            {
                if (line.Length > 0)
                {
                    currentString += line + " ";
                }
                else
                {
                    decodedLines.Add(currentString);
                    currentString = "";
                }
            }
            decodedLines.Add(currentString);

            long star1 = 0;
            long star2 = 0;

            foreach (string line in decodedLines)
            {
                if (Star1Decoder(line))
                {
                    star1++;
                    if (Star2Decoder(line))
                    {
                        star2++;
                    }
                }
            }

            Console.WriteLine("Star 1 {0}", star1);
            Console.WriteLine("Star 2 {0}", star2);
        }
示例#7
0
        public void Load(string file, FileLoaders.IFileLoader loader)
        {
            ClearEntities();
            ClearZones();
            ClearHotspots();

            if (loader is FileLoaders.Scene)
            {
                var scene = (SadConsole.Game.Scene)loader.Load(file);
                textSurface = scene.BackgroundSurface;
                consoleWrapper.TextSurface = textSurface;

                foreach (var item in scene.Objects)
                    LoadEntity(item);

                foreach (var zone in scene.Zones)
                    LoadZone(zone);

                foreach (var spot in scene.Hotspots)
                    LoadHotspot(spot);

                if (EditorConsoleManager.ActiveEditor == this)
                    EditorConsoleManager.UpdateBorder(consoleWrapper.Position);
            }

            textSurface.Font = Settings.Config.ScreenFont;
            Title = Path.GetFileName(file);

            // Update the layer management panel
            layerManagementPanel.SetLayeredTextSurface(textSurface);
        }
        private static void LoadEditor(string file, FileLoaders.IFileLoader loader)
        {
            Editors.IEditor editor = null;

            if (loader is FileLoaders.LayeredTextSurface || loader is FileLoaders.TextSurface)
            {
                editor = new Editors.LayeredConsoleEditor();
                AddEditor(editor, false);
                editor.Load(file, loader);
            }
            else if (loader is FileLoaders.GameObject)
            {
                editor = new Editors.GameObjectEditor();
                AddEditor(editor, false);
                editor.Load(file, loader);
            }
            else if (loader is FileLoaders.Scene)
            {
                editor = new Editors.SceneEditor();
                AddEditor(editor, false);
                editor.Load(file, loader);
            }
            if (editor != null)
            {
                editor.RenderedConsole.TextSurface.RenderArea = new Rectangle(0, 0, InnerEmptyBounds.Width, InnerEmptyBounds.Height);
                ChangeActiveEditor(editor);
            }

            topBarPane.IsVisible = true;
            ToolsPane.IsVisible = true;
            scrollerContainer.IsVisible = true;
        }
        public void Load(string file, FileLoaders.IFileLoader loader)
        {
            if (loader is FileLoaders.TextSurface)
            {
                // Load the plain surface
                TextSurface surface = (TextSurface)loader.Load(file);

                // Load up a new layered text surface
                textSurface = new LayeredTextSurface(surface.Width, surface.Height, 1);

                // Setup metadata
                LayerMetadata.Create("main", false, false, true, textSurface.GetLayer(0));

                // Use the loaded surface
                textSurface.ActiveLayer.Cells = surface.Cells;
                textSurface.SetActiveLayer(0);

                // Set the text surface as the one we're displaying
                consoleWrapper.TextSurface = textSurface;

                // Update the border
                if (EditorConsoleManager.ActiveEditor == this)
                    EditorConsoleManager.UpdateBorder(consoleWrapper.Position);
            }
            else if (loader is FileLoaders.LayeredTextSurface)
            {
                textSurface = (LayeredTextSurface)loader.Load(file);
                consoleWrapper.TextSurface = textSurface;

                if (EditorConsoleManager.ActiveEditor == this)
                    EditorConsoleManager.UpdateBorder(consoleWrapper.Position);
            }

            textSurface.Font = Settings.Config.ScreenFont;
            Title = System.IO.Path.GetFileName(file);

            // Update the layer management panel
            layerManagementPanel.SetLayeredTextSurface(textSurface);
        }
示例#10
0
        static void Main(string[] args)
        {
            FileLoaders   fileLoaders = new FileLoaders(args);
            List <string> input       = fileLoaders.LoadStrings();

            uint        maxId = 0;
            List <uint> ids   = new List <uint>();

            foreach (string line in input)
            {
                uint row = 0, col = 0;
                int  counter = 0;
                foreach (char c in line)
                {
                    if (counter <= 6)
                    {
                        if (c == 'F')
                        {
                            row = row ^ 0;
                        }
                        if (c == 'B')
                        {
                            row = row ^ 1;
                        }

                        if (counter < 6)
                        {
                            row = row << 1;
                        }
                    }
                    else
                    {
                        if (c == 'L')
                        {
                            col = col ^ 0;
                        }
                        if (c == 'R')
                        {
                            col = col ^ 1;
                        }

                        if (counter < 9)
                        {
                            col = col << 1;
                        }
                    }
                    counter++;
                }

                uint id = row * 8 + col;
                ids.Add(id);
                if (id > maxId)
                {
                    maxId = id;
                }
                Console.WriteLine("Row is {0}, column = {1}, ID = {2}", row, col, id);
            }

            ids.Sort();
            uint star2 = 0;

            for (int i = 0; i < ids.Count; i++)
            {
                if (ids[i + 1] != ids[i] + 1)
                {
                    star2 = ids[i] + 1;
                    break;
                }
            }
            Console.WriteLine("Part 1 answer is {0}", maxId);
            Console.WriteLine("Part 2 answer is {0}", star2);
        }
示例#11
0
        public void Load(string file, FileLoaders.IFileLoader loader)
        {
            if (loader is FileLoaders.GameObject)
            {
                SetEntity((GameObject)((FileLoaders.GameObject)loader).Load(file));
                Title = System.IO.Path.GetFileName(file);

            }
        }