52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System.Globalization;
|
|
|
|
namespace part1;
|
|
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
int sum = 0;
|
|
|
|
string letters = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
Dictionary<string, int> numbers = new() {
|
|
{"one", 1},
|
|
{"two", 2},
|
|
{"three", 3},
|
|
{"four", 4},
|
|
{"five", 5},
|
|
{"six", 6},
|
|
{"seven", 7},
|
|
{"eight", 8},
|
|
{"nine", 9}
|
|
};
|
|
|
|
StreamReader sr = new StreamReader("input");
|
|
String line = sr.ReadLine();
|
|
//Continue to read until you reach end of file
|
|
while (line != null)
|
|
{
|
|
line = line.ToLower();
|
|
|
|
foreach(var number in numbers) {
|
|
line = line.Replace(number.Key, number.Value.ToString());
|
|
}
|
|
|
|
foreach(char letter in letters) {
|
|
line = line.Replace(letter.ToString(), string.Empty);
|
|
}
|
|
|
|
sum += Int32.Parse(line[0].ToString()) * 10;
|
|
sum += Int32.Parse(line.Last().ToString());
|
|
|
|
Console.WriteLine($"Line: {line} - Sum: {sum}");
|
|
line = sr.ReadLine();
|
|
}
|
|
//close the file
|
|
sr.Close();
|
|
|
|
Console.WriteLine($"Total Sum: {sum}");
|
|
}
|
|
}
|