public void FindFive() { if (DecodedDigits[1] != null && DecodedDigits[4] != null) { DecodedDigits[5] = Digits.Where(x => x.Length == 5 && x.Intersect(DecodedDigits[1]).Count() == 1 && x.Intersect(DecodedDigits[4]).Count() == 3).First(); } }
public static long AnyToDec(string number, int radix) { const string Digits = "0123456789ABCDEF"; if (String.IsNullOrEmpty(number)) { return(0); } number = number.ToUpperInvariant(); long result = 0; long multiplier = 1; for (int i = number.Length - 1; i >= 0; i--) { char c = number[i]; int digit = Digits.IndexOf(c); result += digit * multiplier; multiplier *= radix; } return(result); }
public void Find6and0() { var hs1 = new HashSet <char>(Digits[1].ToCharArray()); var coll = UniqueValues.Where(uv => uv.Key.Length == 6).ToList(); foreach (var uv in coll) { var hs = new HashSet <char>(Digits[8].ToCharArray()); hs.ExceptWith(uv.Key.ToCharArray()); char ch = hs.Single(); if (hs1.Contains(ch)) { Digits.Add(6, uv.Key); C = ch; } else if (Digits[9] == uv.Key) { // 9 already found ; } else { // D D = ch; Digits.Add(0, uv.Key); } } }
public void SumDigits(string text, int expected) { Digits digits = new Digits(text); var result = digits.SumDigits(); Assert.AreEqual(expected, result); }
public void FindNine() { if (Digits is not null && Digits.Count > 0) { DecodedDigits[9] = Digits.Where(x => x.Length == 6 && x.Intersect(DecodedDigits[1]).Count() == 2 && x.Intersect(DecodedDigits[4]).Count() == 4).First(); } }
public void FindZero() { if (DecodedDigits[1] != null && DecodedDigits[4] != null) { DecodedDigits[0] = Digits.Where(x => x.Length == 6 && x.Intersect(DecodedDigits[1]).Count() == 2 && x.Intersect(DecodedDigits[4]).Count() == 3).First(); } }
/// <summary> /// Initialize the TextBox to support user input including validation. /// Wrapper method with predefined binding. Can be used to use converters with the binding. /// </summary> /// <param name="tb">The TextBox we want to setup.</param> /// <param name="binding">The binding we want to use with the Text property of the TextBox.</param> /// <param name="min">Minimum valid user value.</param> /// <param name="max">Maximum valid user value.</param> /// <param name="handleUserInput">The function which handles the user input.</param> public static void InitUserInputField(TextBox tb, Binding binding, int min, int max, KeyEventHandler handleUserInput) { tb.KeyDown += handleUserInput; binding.ValidationRules.Add(new UserInputValidationRule(min, max)); tb.SetBinding(TextBox.TextProperty, binding); tb.MaxLength = Digits.GetAmountOfDigits(max); }
public static bool TryBase58Decode(this string s, out byte[] decodedData, out string failureReason) { // Decode Base58 string to BigInteger BigInteger intData = 0; for (int i = 0; i < s.Length; i++) { int digit = Digits.IndexOf(s[i]); //Slow if (digit < 0) { failureReason = string.Format("Invalid Base58 character `{0}` at position {1}", s[i], i); decodedData = null; return(false); } intData = intData * 58 + digit; } // Encode BigInteger to byte[] // Leading zero bytes get encoded as leading `1` characters int leadingZeroCount = s.TakeWhile(c => c == '1').Count(); var leadingZeros = Enumerable.Repeat((byte)0, leadingZeroCount); var bytesWithoutLeadingZeros = intData.ToByteArray() .Reverse() // to big endian .SkipWhile(b => b == 0); //strip sign byte decodedData = leadingZeros.Concat(bytesWithoutLeadingZeros).ToArray(); failureReason = string.Empty; return(true); }
public override int GetHashCode() { unchecked { return(((Digits != null ? Digits.GetHashCode() : 0) * 397) ^ IsPositive.GetHashCode()); } }
public static int PinToInt(string pin) { const string Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int radix = 26; if (String.IsNullOrEmpty(pin)) { return(0); } // Make sure pin is in upper case pin = pin.ToUpperInvariant(); int result = 0; int multiplier = 1; for (int i = pin.Length - 1; i >= 0; i--) { char c = pin[i]; int digit = Digits.IndexOf(c); if (digit == -1) { throw new ArgumentException("Invalid character in the pin", "pin"); } result += digit * multiplier; multiplier *= radix; } return(result); }
/// <summary> /// Method to trigger the digitsauth button with country extension /// </summary> private void TriggerDigitsAuthButton() { AuthConfig.Builder authConfigBuilder = new AuthConfig.Builder() .WithAuthCallBack(this) .WithPhoneNumber("+91"); Digits.Authenticate(authConfigBuilder.Build()); }
void ReadFromFile() { Console.WriteLine("Pass the full path of a file with data"); string input; do { input = Console.ReadLine(); if (!File.Exists(input)) { Console.WriteLine("The passed file doesn't exist"); } } while (!File.Exists(input)); TextReader textReader = new StreamReader(input); string dataFromFile = textReader.ReadToEnd().ToString(); foreach (char character in dataFromFile) { if (char.IsDigit(character)) { Digits.Add(Double.Parse(character.ToString())); } } }
/// <summary> /// Executes this expression. /// </summary> /// <param name="parameters">An object that contains all parameters and functions for expressions.</param> /// <returns> /// A result of the execution. /// </returns> /// <seealso cref="ExpressionParameters" /> public override object Execute(ExpressionParameters parameters) { var arg = (double)Argument.Execute(parameters); var digits = Digits != null ? (int)(double)Digits.Execute(parameters) : 0; return(Math.Round(arg, digits, MidpointRounding.AwayFromZero)); }
static void Main() { Console.Write("Enter a digit: "); int input = int.Parse(Console.ReadLine()); Digits dig = (Digits)input; switch (input) { case (int)Digits.Zero: case (int)Digits.One: case (int)Digits.Two: case (int)Digits.Three: case (int)Digits.Four: case (int)Digits.Five: case (int)Digits.Six: case (int)Digits.Seven: case (int)Digits.Eight: case (int)Digits.Nine: Console.WriteLine(dig); break; default: Console.WriteLine("Incorrect input!!!"); break; } }
/// <summary> /// Adapted Unsigned-Base58-Version of Pavel Vladovs ArbitraryToDecimalSystem function. /// See: https://www.pvladov.com/2012/07/arbitrary-to-decimal-numeral-system.html /// </summary> /// <param name="base58String"></param> /// <returns></returns> public static ulong Base58StringToUDecimal(string base58String) { const int FixedRadix = 58; const string Digits = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; if (String.IsNullOrEmpty(base58String)) { return(0); } ulong result = 0; ulong multiplier = 1; for (int i = base58String.Length - 1; i >= 0; i--) { char c = base58String[i]; int digit = Digits.IndexOf(c); if (digit == -1) { throw new ArgumentException( "Invalid character in the arbitrary numeral system number", "number"); } result += (uint)digit * multiplier; multiplier *= FixedRadix; } return(result); }
public void Normalize() { var i = 0; var per = 0; while (i < Digits.Count) { Digits[i] += per; per = Digits[i] / Base; if (per > 0) { Digits[i] = Digits[i] % Base; } i++; } while (per > 0) { var temp = per / Base; if (temp > 0) { Digits.Add(per % Base); per = temp; } else { Digits.Add(per); } } }
public InfoRecord[] GetInfoRecords(ITranslationManager tm) { const string tg = "Statistics"; var records = new List <InfoRecord> { new InfoRecord { Name = tm.T(tg, "Type"), Value = InstrType.ToString() }, new InfoRecord { Name = tm.T(tg, "Comment"), Value = Comment }, new InfoRecord { Name = tm.T(tg, "Digits"), Value = Digits.ToString(CultureInfo.InvariantCulture) }, new InfoRecord { Name = tm.T(tg, "Point value"), Value = Point.ToString("0.#####") }, new InfoRecord { Name = tm.T(tg, "Lot size"), Value = LotSize.ToString(CultureInfo.InvariantCulture) }, new InfoRecord { Name = tm.T(tg, "Spread"), Value = Spread.ToString("F2") + " " + tm.T(tg, "points") }, new InfoRecord { Name = tm.T(tg, "Swap long"), Value = SwapLong.ToString("F2") + " " + tm.T(tg, SwapType.ToString().ToLower()) }, new InfoRecord { Name = tm.T(tg, "Swap short"), Value = SwapShort.ToString("F2") + " " + tm.T(tg, SwapType.ToString().ToLower()) }, new InfoRecord { Name = tm.T(tg, "Commission"), Value = Commission.ToString("F2") + " " + tm.T(tg, CommissionType.ToString().ToLower()) }, new InfoRecord { Name = tm.T(tg, "Slippage"), Value = Slippage.ToString("F2") + " " + tm.T(tg, "points") } }; return(records.ToArray()); }
public void Of_String_WhenStringIsEmpty_ThrowsException() { // Arrange // Act // Assert Assert.That(() => Digits.Of(string.Empty), Throws.InstanceOf <ArgumentException>()); Assert.That(() => Digits.Of(null), Throws.InstanceOf <ArgumentNullException>()); }
public int?Log2() { if (IsZero()) { return(null); } return(Digits.LastIndexOf(true)); }
public void Of_String_WhenStringIncludesNonDigit_ThrowsException() { // Arrange // Act // Assert Assert.That(() => Digits.Of("a"), Throws.InstanceOf <ArgumentException>()); Assert.That(() => Digits.Of("-"), Throws.InstanceOf <ArgumentException>()); }
public void Of_int_WhenIntIsNegative_ThrowsException() { // Arrange // Act // Assert Assert.That(() => Digits.Of(-1), Throws.InstanceOf <ArgumentOutOfRangeException>()); Assert.That(() => Digits.Of(-2), Throws.InstanceOf <ArgumentOutOfRangeException>()); }
/// <summary> /// Trims leading zeros. Modifies (not copies) the instance. /// </summary> /// <returns>the same instance but with trimmed leading zeros</returns> private BigInt Trim() { while (Digits.Count > 1 && Digits.Last() != true) { _digits.RemoveLast(); } return(this); }
static string LastDigit(int my) { int lastDig = my % 10; Digits someDigits = (Digits)lastDig; string result = Convert.ToString(someDigits); return(result); }
public long getNext() { Digits currentDigits; Digits newDigits; Digits digits; digits = new Digits(this.x); byte counter = digits.nextMax(); for (byte i = 0; i <= counter; i++) { switch (digits.nextMax() + 3) { case 3: if (this.x < 5000000000L) this.x += 5000000000L; goto case 4; case 4: this.x = ((long)Math.Floor((double)((this.x * this.x) / 100000L))) % 10000000000L; goto case 5; case 5: this.x = (1001001001L * this.x) % 10000000000L; goto case 6; case 6: if (this.x < 100000000L) this.x += 9814055677L; else this.x = 10000000000L - this.x; goto case 7; case 7: long first5 = this.x % 100000; this.x = first5 * 100000 + (this.x / 100000); goto case 8; case 8: this.x = (1001001001L * this.x) % 10000000000L; goto case 9; case 9: currentDigits = new Digits(this.x); for (int j = 0; j < currentDigits.digits.Count; j++) if (0 != currentDigits.digits[j]) currentDigits.digits[j]--; goto case 10; case 10: if (this.x < 100000L) this.x = this.x * this.x + 99999L; else this.x -= 99999L; goto case 11; case 11: while (this.x < 1000000000L) this.x *= 10; goto case 12; case 12: this.x = ((long)Math.Floor((double)((this.x * (this.x - 1)) / 100000L))) % 10000000000L; digits = new Digits(this.x); break; } } return this.x; }
void CalculateProbabilities() { var groups = Digits.GroupBy(i => i); foreach (var group in groups) { InputProbabilities.Add(Math.Round((double)group.Count() / Digits.Count(), 4) * 100); } }
public RecordFileCommand(string fileName, string format, Digits escapeDigits, int timeout, int?offsetSamples, bool beep, int?silence) { _fileName = fileName; _format = format; _escapeDigits = escapeDigits; _timeout = timeout; _offsetSample = offsetSamples; _beep = beep; _silence = silence; }
public override bool Equals(object obj) { var anotherObject = obj as Language; return(Keywords.SequenceEqual(anotherObject.Keywords) && Delimiters.SequenceEqual(anotherObject.Delimiters) && AllowedSymbols.SequenceEqual(anotherObject.AllowedSymbols) && Digits.SequenceEqual(anotherObject.Digits) && ComplexDelimiters.SequenceEqual(anotherObject.ComplexDelimiters)); }
public void can_convert_digits_to_file_strings(int input, string expectedOutput) { var output = Digits.ToFileString(input); output.Should().Be( expectedOutput, "\nexpected: '{0}'\nactual: '{1}'\n".Fmt( expectedOutput.Replace("digits/", "").Replace(".wav", "") , output.Replace("digits/", "").Replace(".wav", ""))); }
public NumberGenerator() { for (var i = 0; i < 10; i++) { Digits.Add(i); } for (var i = 0; i < Constants.MatrixNumberOfColumns * Constants.MatrixNumberOfRows; i++) { MatrixIndexes.Add(i); } }
public void Push(Digits digit) { var absInput = (decimal)digit; var input = (_representation < 0m) ? -absInput : absInput; var newValue = _representation * 10m + input; if (newValue <= 9999999990m) { _representation = newValue; } }
public void PressDigit(Digits digit) { MaybeFlush(); if (_resetScan) { _mainRegister.Clear(); _resetScan = false; } _mainRegister.Push(digit); }
private static int[,] GetDigitValues(int digit) { int[,] digitValues; bool digitFound = Digits.TryGetValue(digit, out digitValues); if (!digitFound) { throw new ArgumentException("incorrect digit"); } return(digitValues); }
/// <summary> /// To add the pressed digit to the current number /// </summary> public void AddDigit(Digits pressedDigit) { EqualBtnPressed_Check(); AdditionalOperationBtnPressed_Check(); if (CurrentNumberSizeCheck(currentData.CurrentNumber)) { currentData.CurrentNumber = currentData.CurrentNumber != ((int)Digits.Zero).ToString() ? (currentData.CurrentNumber + (int)pressedDigit) : ((int)pressedDigit).ToString(); } buttonsState.NumberPadBtnPressed_Change(true); }
public void WriteCharacter(char character, Digits digit) { byte actualDigit; switch (digit) { case Digits.First: actualDigit = DIGIT_1; break; case Digits.Second: actualDigit = DIGIT_2; break; case Digits.Third: actualDigit = DIGIT_3; break; case Digits.Fourth: actualDigit = DIGIT_4; break; default: throw new ArgumentOutOfRangeException("digit"); } WriteChar(_device, character, actualDigit); }
/// <summary> /// Initialize an OTP instance with the shared secret generated on Registration process /// </summary> /// <param name="secret"> Shared secret </param> /// <param name="clock"> Clock responsible for retrieve the current interval </param> /// <param name="digits"> Number of digits of generated OTP codes </param> public Totp(string secret, Clock clock, Digits digits = Digits.Six) { this.secret = secret; this.clock = clock; this.digits = digits; }
private Number(Digits digits) { _value = digits.AsWholeNumber; }
/// <summary> /// Initialize an OTP instance with the shared secret generated on Registration process /// </summary> /// <param name="secret"> Shared secret </param> /// <param name="digits"> Number of digits of generated OTP codes </param> public Totp(string secret, Digits digits = Digits.Six) : this(secret, new Clock(), digits) { }