Example #1
0
        public void WriteToFile(string outputName, BookScanningOutput bookScanningOutputModel)
        {
            var          outputPath = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "\\Data\\Output\\" + outputName + ".out";
            StreamWriter sr         = new StreamWriter(outputPath, false);

            sr.WriteLine(bookScanningOutputModel.NumberOfScannedLibraries);
            bookScanningOutputModel.ScannedLibraries.ForEach(scannedLibrary =>
            {
                sr.WriteLine(scannedLibrary.Item1.ToString() + " " + scannedLibrary.Item2.Count().ToString());
                sr.WriteLine(String.Join(' ', scannedLibrary.Item2));
            });
            sr.Close();

            //Archive - TODO
            var score       = bookScanningOutputModel.Score;
            var archivePath = Directory.GetParent(Environment.CurrentDirectory).Parent.Parent.FullName + "\\Data\\Archive\\" + outputName.Substring(0, outputName.Length - 3);

            if (!Directory.Exists(archivePath))
            {
                Directory.CreateDirectory(archivePath);
            }

            var          fileArchivePath = archivePath + "\\" + score.ToString();
            StreamWriter srArchive       = new StreamWriter(outputPath, false);

            srArchive.WriteLine(bookScanningOutputModel.NumberOfScannedLibraries);
            bookScanningOutputModel.ScannedLibraries.ForEach(scannedLibrary =>
            {
                srArchive.WriteLine(scannedLibrary.Item1.ToString() + " " + scannedLibrary.Item2.Count().ToString());
                srArchive.WriteLine(String.Join(' ', scannedLibrary.Item2));
            });
            srArchive.Close();
        }
Example #2
0
        public static int GetScore(BookScanning bookScanning, BookScanningOutput bookScanningOutput)
        {
            scannedBooks.Clear();
            startingDay = 0;
            int score = 0;

            for (int i = 0; i < bookScanningOutput.NumberOfScannedLibraries; i++)
            {
                libraryId    = bookScanningOutput.ScannedLibraries[i].Item1;
                startingDay += bookScanning.Libraries[libraryId].SigningTime;
                booksPerDay  = bookScanning.Libraries[libraryId].BooksShippedPerDay;
                var enumerator = bookScanningOutput.ScannedLibraries[i].Item2.GetEnumerator();
                enumerator.MoveNext();

                bool valid = true;

                for (int j = 0; j < bookScanning.NumberOfDays - startingDay; j++)
                {
                    if (!valid)
                    {
                        break;
                    }

                    for (int k = 0; k < booksPerDay; k++)
                    {
                        if (!valid)
                        {
                            break;
                        }

                        int book = enumerator.Current;
                        if (!scannedBooks.Contains(book))
                        {
                            scannedBooks.Add(book);
                        }
                        if (!enumerator.MoveNext())
                        {
                            valid = false;
                        }
                    }
                }
            }

            foreach (var book in scannedBooks)
            {
                score += bookScanning.BookScores[book];
            }
            return(score);
        }
Example #3
0
        static void Main(string[] args)
        {
            //RunLevel("a.txt");
            //RunAllLevels();
            DataManager DataManager = new DataManager();
            var         model       = DataManager.ReadFromFile("a.txt");

            var outputModel = new BookScanningOutput();

            outputModel.NumberOfScannedLibraries = 2;
            outputModel.ScannedLibraries.Add((1, new List <int> {
                5, 2, 3
            }));
            outputModel.ScannedLibraries.Add((0, new List <int> {
                0, 1, 2, 3, 4
            }));
            Console.WriteLine(Scoring.GetScore(model, outputModel));
            Console.Read();
        }