using System; using System.Linq; using System.Collections.Generic; namespace Kumite { public class Problem { public static int SumDigitsOf(long integer) { return integer.GetDigits().Sum(); } } public static class LongExtensions { public static IEnumerable<int> GetDigits(this long number) { number = Math.Abs(number); while (number > 9) { yield return (int)(number % 10); number /= 10; } yield return (int)number; } } }
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace Kumite
- {
public class Problem- public class Problem
- {
- public static int SumDigitsOf(long integer)
- {
public static int SumDigitsOf(long integer){return Math.Abs(integer).ToString().Sum(digit => digit - '0');}- return integer.GetDigits().Sum();
- }
- }
- public static class LongExtensions
- {
- public static IEnumerable<int> GetDigits(this long number)
- {
- number = Math.Abs(number);
- while (number > 9)
- {
- yield return (int)(number % 10);
- number /= 10;
- }
- yield return (int)number;
- }
- }
- }