Beispiel #1
0
 private void Initialize()
 {
     InputInstructions = InputFileReader.GetInput($"Year2019/Inputs/Day{Day}.txt")[0]
                         .Split(',')
                         .Select(x => long.Parse(x))
                         .ToList();
 }
Beispiel #2
0
 public Solver()
 {
     _program = InputFileReader.GetInput($"Year2019/Inputs/Day{Day}.txt")[0]
                .Split(',')
                .Select(x => long.Parse(x))
                .ToList();
 }
Beispiel #3
0
        public void 設定ファイルと入力ファイル読み込み出力する()
        {
            var conf = new ConfigReader("C:\\Users\\kero\\source\\repos\\MyApp\\UnitTestProject1\\テストデータ\\入力データ\\設定ファイル.txt");

            IReaderRepository input = new InputFileReader("C:\\Users\\kero\\source\\repos\\MyApp\\UnitTestProject1\\テストデータ\\入力データ\\INPUT.txt",
                                                          conf.GetLoopEntity());

            IWriterRepository writer = new OutputXMLFile("d:\\test\\sample.xml");

            writer.Open().IsTrue();
            input.Open();
            var line = input.GetLine();

            foreach (var data in line.DataLists)
            {
                Console.WriteLine(data.Value);
            }
            line.IsNotNull();

            writer.SetLine(line);
            line = input.GetLine();

            foreach (var data in line.DataLists)
            {
                Console.WriteLine(data.Value);
            }
            writer.SetLine(line);
            writer.Close();
        }
        public void TestReadUntilNextKeywordWithValidKeywords()
        {
            InputFileReader reader = InputFileReader.GetReader(TestFileNameContents.Example2FileName);

            Assert.AreEqual("the", reader.ReadUntilNextKeyword("the", "canal"));
            Assert.AreEqual("canal", reader.ReadUntilNextKeyword("panama", "canal"));
        }
Beispiel #5
0
        public Solver()
        {
            var input = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                        .ToList();

            Image image = null;

            foreach (var line in input)
            {
                if (line.StartsWith("Tile "))
                {
                    if (image != null)
                    {
                        _images.Add(image);
                    }
                    image = new Image(int.Parse(line.Replace("Tile ", string.Empty).Replace(":", string.Empty)));
                }
                else if (line.StartsWith(".") || line.StartsWith("#"))
                {
                    image.Content.Add(line);
                }
            }

            _images.Add(image);
            _images.ForEach(image => image.GetSidesWithInversion().ForEach(x =>
            {
                if (!_sides.TryAdd(x, new List <int> {
                    image.Id
                }))
                {
                    _sides[x].Add(image.Id);
                }
            }));
        }
Beispiel #6
0
        private void Initialize()
        {
            _playerOne = new Queue <int>();
            _playerTwo = new Queue <int>();
            var input    = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt").ToList();
            var playerId = 0;

            foreach (var line in input)
            {
                if (line.StartsWith("Player"))
                {
                    playerId++;
                }
                else if (line != string.Empty)
                {
                    if (playerId == 1)
                    {
                        _playerOne.Enqueue(int.Parse(line));
                    }
                    else
                    {
                        _playerTwo.Enqueue(int.Parse(line));
                    }
                }
            }
        }
Beispiel #7
0
        public Solver()
        {
            _orbitMap = new Dictionary <string, Node>();
            var input = InputFileReader.GetInput($"Year2019/Inputs/Day{Day}.txt");

            BuildOrbitMap(input);
        }
Beispiel #8
0
 public Solver()
 {
     AsteroidMap = InputFileReader
                   .GetInput($"Year2019/Inputs/Day{Day}.txt")
                   .Select(x => x.ToCharArray())
                   .ToList();
 }
Beispiel #9
0
        public Solver()
        {
            var lines = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                        .ToList();

            foreach (var line in lines)
            {
                var split       = line.Split(" (");
                var ingredients = split[0].Split(" ");
                var recipe      = new Recipe();
                recipe.Ingredients.AddRange(ingredients);

                split[1]
                .Replace("contains ", string.Empty)
                .Replace(")", string.Empty)
                .Split(", ").ToList()
                .ForEach(x =>
                {
                    var a = _alergens.FirstOrDefault(a => a.Name == x);
                    if (a == null)
                    {
                        a = new Alergen(x);
                        _alergens.Add(a);
                    }

                    a.Recipes.Add(recipe);
                    recipe.Alergens.Add(a);
                });

                _recipes.Add(recipe);
            }
        }
Beispiel #10
0
        public Solver()
        {
            var switchToMessagePopulation = false;
            var input = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                        .ToList();

            foreach (var line in input)
            {
                if (line == string.Empty)
                {
                    switchToMessagePopulation = true;
                    continue;
                }

                if (switchToMessagePopulation)
                {
                    _messages.Add(line);
                }
                else
                {
                    var split = line.Split(": ");
                    _ruleBook.Add(int.Parse(split[0]), line.Contains("\"") ? new FixedCharacterRule(split[1]) : new PositionRule(split[1], _ruleBook));
                }
            }
        }
Beispiel #11
0
        public Solver()
        {
            var input = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt");
            var mode  = 0;

            foreach (var line in input)
            {
                mode = line == "your ticket:" ? 1 : line == "nearby tickets:" ? 2 : mode;

                if (line == string.Empty || line == "your ticket:" || line == "nearby tickets:")
                {
                    continue;
                }

                switch (mode)
                {
                case 0:
                    var split      = line.Split(':');
                    var valueRange = split[1].Split(" or ").Select(x => new Range(int.Parse(x.Split('-')[0]), int.Parse(x.Split('-')[1])));

                    _ticketProperties.Add(new TicketProperty(split[0], valueRange));
                    break;

                case 1:
                    _myTicket = line.Split(',').Select(x => int.Parse(x)).ToList();
                    break;

                case 2:
                    _nearbyTickets.Add(line.Split(',').Select(x => int.Parse(x)).ToList());
                    break;
                }
            }
        }
Beispiel #12
0
 public Solver()
 {
     _joltages = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                 .Select(i => int.Parse(i))
                 .OrderBy(i => i)
                 .ToList();
 }
        public void TestConstructor()
        {
            InputFileReader reader = InputFileReader.GetReader(TestFileNameContents.Example2FileName);

            //If no exception is thrown, this test passes
            Assert.IsTrue(true);
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            var strings  = InputFileReader.ReadAllLines("Input.txt");
            var unlocker = new Unlocker(strings);

            Console.WriteLine(unlocker.GenerateSectorSum());
            unlocker.GetSectorIdOfRequiredRoom();
            Console.ReadLine();
        }
Beispiel #15
0
        public static void Main()
        {
            var code = new Code(InputFileReader.ReadAllLines("Input.txt")[0]);

            var res = code.DecompressAndCount2();

            Console.WriteLine(res);
            Console.ReadLine();
        }
Beispiel #16
0
        public void InputFileReader_WhenFileIsEmptyString_ThrowsException()
        {
            InputFileReader fileReader = new InputFileReader();

            ActualValueDelegate <List <DocumentedAssembly> > test =
                () => fileReader.Read(string.Empty, string.Empty);

            Assert.That(test, Throws.ArgumentNullException);
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            var operations = InputFileReader.ReadAllLines("Input.txt");

            var op = new Operator(operations);

            op.Run();
            Console.WriteLine(op.GetResult('a'));
            Console.ReadLine();
        }
        public void TestGetRangeOfWordsWithValidRange()
        {
            InputFileReader reader = InputFileReader.GetReader(TestFileNameContents.Example2FileName);

            //Have to read before we can get the range of words
            reader.ReadUntilNextKeyword("the", "man");

            Assert.AreEqual(2, reader.GetRangeOfWords(2).Length);
            Assert.AreEqual("the", reader.GetRangeOfWords(2)[0]);
            Assert.AreEqual("man", reader.GetRangeOfWords(2)[1]);
        }
        private void InitialiseFromProject()
        {
            Project project = LiveDocumentorFile.Singleton.UnerlyingProject;
            ObservableCollection <ProjectEntry> entries = new ObservableCollection <ProjectEntry>();

            // store original list so we can check for changes.
            originalFiles.AddRange(project.Files);
            originalRemovedAssemblies.AddRange(project.RemovedAssemblies);

            // build the entry list
            foreach (string file in project.Files)
            {
                ProjectEntry parent = new ProjectEntry();
                parent.Tag  = file;
                parent.Name = System.IO.Path.GetFileName(file);
                parent.Type = "parent";

                string extension = System.IO.Path.GetExtension(file);
                switch (extension)
                {
                case ".sln":
                    parent.Icon = "solution.png";
                    break;

                case ".dll":
                    parent.Icon     = "library.png";
                    parent.Children = null;
                    break;

                default:
                    parent.Icon = "project.png";
                    break;
                }

                if (parent.Children != null)
                {
                    List <DocumentedAssembly> libraries = new InputFileReader().Read(file, project.Configuration);
                    foreach (DocumentedAssembly assembly in libraries)
                    {
                        ProjectEntry child = new ProjectEntry();
                        child.Name   = assembly.Name;
                        child.Tag    = string.Format("{0}\\{1}", parent.Name, child.Name);
                        child.Hidden = project.RemovedAssemblies.Contains(child.Tag);
                        child.Type   = "child";
                        parent.Children.Add(child);
                    }
                }

                entries.Add(parent);
            }

            this.Entries             = entries;
            this.manager.ItemsSource = this.Entries;
        }
Beispiel #20
0
        public static void Main()
        {
            _rawTriangles = InputFileReader.ReadAllLines("Input.txt");
            _triangles    = new List <Triangle>();

            Task1();
            _triangles.Clear();
            Task2();

            Console.ReadLine();
        }
Beispiel #21
0
        public void InputFileReader_WhenFileExtensionIsInvalid_ThrowsException()
        {
            const string TestFileName = "invalid.extension";

            InputFileReader fileReader = new InputFileReader();

            ActualValueDelegate <List <DocumentedAssembly> > test =
                () => fileReader.Read(TestFileName, string.Empty);

            Assert.That(test, Throws.ArgumentException);
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            var strings          = InputFileReader.ReadAllLines("Input.txt");
            var convertedStrings = InputTransposer.Convert(strings);

            var simplifiedString1 = Simplifier.Simplify(convertedStrings);
            var simplifiedString2 = Simplifier.Simplify(convertedStrings, false);

            Console.WriteLine("Task 1: " + simplifiedString1);
            Console.WriteLine("Task 2: " + simplifiedString2);
            Console.ReadLine();
        }
Beispiel #23
0
        public static void Main()
        {
            var unlocker  = new Unlocker();
            var unlocker2 = new Unlocker(2);

            var inputCodes = InputFileReader.ReadAllLines("Input.txt");

            Console.WriteLine("Task1: " + unlocker.GetCode(inputCodes));
            Console.WriteLine("Task2: " + unlocker2.GetCode(inputCodes));

            Console.ReadLine();
        }
        public void TestReadUntilNextKeywordWithNullKeyword()
        {
            InputFileReader reader = InputFileReader.GetReader(TestFileNameContents.Example2FileName);

            try
            {
                reader.ReadUntilNextKeyword(null, "canal");
            }
            catch (ArgumentException e)
            {
                Assert.AreEqual(ErrorMessageConstants.InvalidKeywordArgumentErrorMessage, e.Message);
            }
        }
        public void TestGetRangeOfWordsWithoutReading()
        {
            InputFileReader reader = InputFileReader.GetReader(TestFileNameContents.Example2FileName);

            try
            {
                reader.GetRangeOfWords(2);
            }
            catch (InvalidOperationException e)
            {
                Assert.AreEqual(ErrorMessageConstants.InputFileReaderGetRangeWithoutReadingErrorMessage, e.Message);
            }
        }
Beispiel #26
0
        public ExtractionResponse RunExtraction()
        {
            List <InputFileItem> inputItemCollection;
            var fileReader = new InputFileReader(_csvDelimiter);

            try
            {
                inputItemCollection = fileReader.GetInputItemCollection(Request.InputFilePath);
            }
            catch (Exception ex)
            {
                Response.GeneralException = ex.GetInnerMostException();
                return(Response);
            }

            var successCnt       = 0;
            var markupAggregator = new MarkupAggregator(
                HttpAgent, VerboseLogger, _hrefRegex, _invalidSiteLinkPatterns);
            var emailExtractor = new EmailExtractor(_emailRegex);
            var fileWriter     = new OutputFileWriter(_csvDelimiter, Request.OutputDirectory);

            foreach (var inputItem in inputItemCollection)
            {
                VerboseLogger.Log($"Extracting from {inputItem.SiteUrl} url...");

                try
                {
                    ProcessInputFileItem(inputItem, markupAggregator, emailExtractor, fileWriter);

                    VerboseLogger.Log($"Extraction completed for {inputItem.SiteUrl} url...");

                    successCnt++;
                }
                catch (Exception ex)
                {
                    var eEx = new ExtractionException("", ex)
                    {
                        InputUrl = inputItem.SiteUrl
                    };

                    VerboseLogger.Log("Extraction failed. Moving to next url...");

                    Response.ExtractionExceptions = Response.ExtractionExceptions ?? new List <ExtractionException>();
                    Response.ExtractionExceptions.Add(eEx);
                }
            }

            Response.SuccessfulExtractions = successCnt;

            return(Response);
        }
Beispiel #27
0
 static void Main(string[] args)
 {
     try
     {
         Program parkingLot = new Program();
         if (args.Length == 1)
         {
             string            filePath         = args[0];
             IInputFileReader  fileReader       = new InputFileReader();
             IValidateFileType validateFileType = new ValidateFileType();
             IExecuteFromFile  fileExecutor     = new ExecuteFromFile(parkingLot._provider, validateFileType, fileReader);
             string            messages         = fileExecutor.Execute(filePath);
             Console.WriteLine(messages);
         }
         else if (args.Length > 1)
         {
             Console.WriteLine("Takes only one argument");
         }
         else
         {
             string result = string.Empty;
             bool   isLive = true;
             while (isLive)
             {
                 string userInputCommand = Console.ReadLine();
                 if (userInputCommand.Equals("exit"))
                 {
                     isLive = false;
                 }
                 else
                 {
                     ICommandExecutor executor = parkingLot._provider.InitExecutor(userInputCommand);
                     if (executor != null)
                     {
                         result = executor.ExecuteCommand(userInputCommand);
                     }
                     else
                     {
                         result = "Invalid Command";
                     }
                     Console.WriteLine(result);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }
Beispiel #28
0
 public Solver()
 {
     _passwords = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                  .Select(x => {
         var parts  = x.Split(' ');
         var policy = parts[0].Split('-');
         return(new CorporatePassword
         {
             Letter = parts[1].Replace(":", string.Empty)[0],
             PolicyField2 = int.Parse(policy[0]),
             PolicyField1 = int.Parse(policy[1]),
             Password = parts[2]
         });
     }).ToList();
 }
Beispiel #29
0
        static void Main(string[] args)
        {
            var input = InputFileReader.ReadAllLines("Input.txt");

            var actions = new List <int>();

            foreach (var s in input)
            {
                actions.Add(int.Parse(s));
            }

            // Task 1:
            var res0 = 0;

            foreach (var action in actions)
            {
                res0 += action;
            }


            // Task 2:
            var freq = 0;
            var res  = 0;

            var allFreqs = new HashSet <int>();

            allFreqs.Add(freq);
            var notFound = true;

            while (notFound)
            {
                foreach (var action in actions)
                {
                    freq += action;
                    if (!allFreqs.Add(freq))
                    {
                        notFound = false;
                        res      = freq;
                        break;
                    }
                }
            }

            // Output:
            Console.WriteLine(res0);
            Console.WriteLine(res);
            Console.ReadLine();
        }
Beispiel #30
0
        public Solver()
        {
            _bags = InputFileReader.GetInput($"Year2020/Inputs/Day{Day}.txt")
                    .Select(line =>
            {
                var ruleSplit = line.Split("contain");

                var content = ParseBagContent(ruleSplit);

                return(new Bag
                {
                    Color = ruleSplit[0].Replace(" bags ", string.Empty),
                    NestedBags = content
                });
            }).ToHashSet();
        }