© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
11 replies
AceChewy

Advent of Code Day 1

I'm not sure why my code isn't accepted even though I'm sure it works:

private int Sum() 
{
   int Overall = 0;

   Console.WriteLine("Enter the calibration document. Enter an empty line to finish.");

   string line;
   while ((line = Console.ReadLine()) != "")
   {
       int firstDigit = 0;
       int lastDigit = 0;

       // Find the first digit
       for (int i = 0; i < line.Length; i++)
       {
           if (Char.IsDigit(line[i]))
           {
               firstDigit = Int32.Parse(line[i].ToString());
               break;
           }
       }

       // Find the last digit
       for (int i = line.Length - 1; i >= 0; i--)
       {
           if (Char.IsDigit(line[i]))
           {
               lastDigit = Int32.Parse(line[i].ToString());
               break;
           }
       }

       Overall += firstDigit  + lastDigit;
   }

   return Overall;
}
private int Sum() 
{
   int Overall = 0;

   Console.WriteLine("Enter the calibration document. Enter an empty line to finish.");

   string line;
   while ((line = Console.ReadLine()) != "")
   {
       int firstDigit = 0;
       int lastDigit = 0;

       // Find the first digit
       for (int i = 0; i < line.Length; i++)
       {
           if (Char.IsDigit(line[i]))
           {
               firstDigit = Int32.Parse(line[i].ToString());
               break;
           }
       }

       // Find the last digit
       for (int i = line.Length - 1; i >= 0; i--)
       {
           if (Char.IsDigit(line[i]))
           {
               lastDigit = Int32.Parse(line[i].ToString());
               break;
           }
       }

       Overall += firstDigit  + lastDigit;
   }

   return Overall;
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Advent of Code Day 1 - Issue with Chars
C#CC# / help
3y ago
✅ Advent of code 🎄🎅🏼
C#CC# / help
3y ago