Sha256: 4e465f32b09f7bd51391d5ce44f6c09f1541fcaa7f9b26d7da6d519deb542d3a
Contents?: true
Size: 569 Bytes
Versions: 98
Compression:
Stored size: 569 Bytes
Contents
using System; using System.Linq; public class Trinary { public static int ToDecimal(string trinary) { if (IsNotValidTrinary(trinary)) return 0; return trinary .Select((c, i) => int.Parse(c.ToString()) * ThreeToThePowerOf(trinary.Length - i - 1)) .Sum(); } private static bool IsNotValidTrinary(string trinary) { return !trinary.All(x => char.IsDigit(x) && int.Parse(x.ToString()) < 3); } private static int ThreeToThePowerOf(int power) { return (int)Math.Pow(3, power); } }
Version data entries
98 entries across 98 versions & 1 rubygems