Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submission: C# #7

Open
veektorh opened this issue Sep 27, 2018 · 0 comments
Open

Submission: C# #7

veektorh opened this issue Sep 27, 2018 · 0 comments

Comments

@veektorh
Copy link

veektorh commented Sep 27, 2018

dotnet core 2.1.302

  • Time : ~ 15s

Hardware :

  Processor Name: Intel Core i5
  Processor Speed: 1.7 GHz
  Number of Processors: 1
  Total Number of Cores: 2
  L2 Cache (per Core):  512KB
  L3 Cache: 3 MB
  Memory: 6 GB

Program

using System;
using System.IO;

namespace SumNumbers
{
    class Program
    {
        static void Main(string[] args)
        {
            SumIntegers();

        }

        public static void SumIntegers()
        {
            var startTime = DateTime.Now;

            //replace with directory path
            var dirPath = Directory.GetCurrentDirectory() + @"\files";

            var folders = Directory.GetDirectories(dirPath);
            long total = 0;

            for (int i = 0; i < folders.Length; i++)
            {
                var folder = folders[i];
                var files = Directory.GetFiles(folder);

                for (int j = 0; j < files.Length; j++)
                {
                    var file = files[j];
                    var fileContent = File.ReadAllLines(file);

                    for (int k = 0; k < fileContent.Length; k++)
                    {
                        var numbers = fileContent[k].Split(',');

                        for (int l = 0; l < numbers.Length; l++)
                        {
                            total += Convert.ToInt64(numbers[l]);
                        }
                    }

                }

            }

            Console.WriteLine("total : " + total);
            Console.WriteLine("Milliseconds : " + (DateTime.Now - startTime).TotalMilliseconds);
        }


    }
}

Output

total : 49947871404
Milliseconds : 15210.5908

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant