def SumDigitsOf(integer): return sum([int(value) for value in str(integer)])
using System;using System.Linq;using System.Collections.Generic;namespace Kumite{public class Problem{public static int SumDigitsOf(long integer) => (int)(from ch in integer.ToString()where Char.IsDigit(ch)select Char.GetNumericValue(ch)).Sum();}}- def SumDigitsOf(integer):
- return sum([int(value) for value in str(integer)])
test.assert_equals(SumDigitsOf(123), 6) test.assert_equals(SumDigitsOf(4), 4) test.assert_equals(SumDigitsOf(444), 12) test.assert_equals(SumDigitsOf(932), 14) test.assert_equals(SumDigitsOf(67), 13) test.assert_equals(SumDigitsOf(12), 3)
namespace TestCases{using NUnit.Framework;using System;using System.Collections.Generic;using System.Linq;[TestFixture]public class SolutionTests{readonly Dictionary<long, int> expected = new Dictionary<long, int>{{ 234, 9 },{ 366, 15 },{ -741, 12 },{ 2021, 5 },{ 1998, 27 },{ 1882, 19 },{ -1492, 16 },{ 999999999, 81 },{ 12345678901234, 55 },{ 99999999999999, 126 }};[Test]public void TestForProblemDescription(){Assert.AreEqual(6, Kumite.Problem.SumDigitsOf(10023));}[Test]public void Test10Samples(){foreach (var pair in expected){Assert.AreEqual(pair.Value, Kumite.Problem.SumDigitsOf(pair.Key));}}}}- test.assert_equals(SumDigitsOf(123), 6)
- test.assert_equals(SumDigitsOf(4), 4)
- test.assert_equals(SumDigitsOf(444), 12)
- test.assert_equals(SumDigitsOf(932), 14)
- test.assert_equals(SumDigitsOf(67), 13)
- test.assert_equals(SumDigitsOf(12), 3)