Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8469295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:11:15+00:00 2026-06-10T16:11:15+00:00

I’m trying to find multiple ways to solve Project Euler’s problem #13 . I’ve

  • 0

I’m trying to find multiple ways to solve Project Euler’s problem #13. I’ve already got it solved two different ways, but what I am trying to do this time is to have my solution read from a text file that contains all of the numbers, from there it converts it and adds the column numbers farthest to the right. I also want to solve this problem in a way such that if we were to add new numbers to our list, the list can contain any amount of rows or columns, so it’s length is not predefined (non array? I’m not sure if a jagged array would apply properly here since it can’t be predefined).

So far I’ve got:

    static void Main(string[] args)
    {

        List<int> sum = new List<int>();

        string bigIntFile = @"C:\Users\Justin\Desktop\BigNumbers.txt";

        
        string result;
    
        StreamReader streamReader = new StreamReader(bigIntFile);

        while ((result = streamReader.ReadLine()) != null)
        {
            for (int i = 0; i < result.Length; i++)
            {
                int converted = Convert.ToInt32(result.Substring(i, 1));
                sum.Add(converted);
            }
        }

    }

which reads the file and converts each character from the string to a single int. I’m trying to think how I can store that int in a collection that is like 2D array, but the collection needs to be versatile and store any # of rows / columns. Any ideas on how to store these digits other than just a basic list? Is there maybe a way I can set up a list so it’s like a 2D array that is not predefined? Thanks in advance!

UPDATE: Also I don’t want to use "BigInteger". That’d be a little too easy to read the line, convert the string to a BigInt, store it in a BigInt list and then sum up all the integers from there.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:11:17+00:00Added an answer on June 10, 2026 at 4:11 pm

    There is no resizable 2D collection built into the .NET framework. I’d just go with the “jagged arrays” type of data structure, just with lists:

    List<List<int>>
    

    You can also vary this pattern by using an array for each row:

    List<int[]>
    

    If you want to read the file a little simpler, here is how:

    List<int[]> numbers =
     File.EnumerateLines(path)
     .Select(lineStr => lineStr.Select(@char => @char - '0').ToArray())
     .ToList();
    

    Far less code. You can reuse a lot of built-in stuff to do basic data transformations. That gives you less code to write and to maintain. It is more extensible and it is less prone to bugs.

    If you want to select a column from this structure, do it like this:

    int colIndex = ...;
    int[] column = numbers.Select(row => row[index]).ToArray();
    

    You can encapsulate this line into a helper method to remove noise from your main addition algorithm.

    Note, that the efficiency of all those patterns is far less than a 2D array, but in your case it is good enough.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.