public INumber Build(INumber referenceNumber, int unitsToReplace, int unitsToShuffle) { var newNumber = (INumber)referenceNumber.Clone(); var random = new Random(); foreach (var unitToInclude in this.unitsToInclude) { newNumber.EditUnit(unitToInclude.Position, unitToInclude.Value); } this.ReplaceUnits(newNumber, unitsToReplace, random); var newUnitsToShuffle = referenceNumber.Units.Count() - unitsToReplace - this.unitsToInclude.Count; if (newUnitsToShuffle > 0) { if (unitsToShuffle < newUnitsToShuffle) { newUnitsToShuffle = unitsToShuffle; } var positionsToShuffle = newNumber.Units .Where(u => !this.unitsToInclude.Select(x => x.Position).Any(p => p == u.Position)) .Where(u => referenceNumber.Units.Any(x => x.Value == u.Value)) .Take(unitsToShuffle) .Select(u => u.Position) .ToList(); this.ShuffleUnits(newNumber, positionsToShuffle, random); } return newNumber; }
public AttemptResult(INumber number, int goods, int regulars, int bads) { this.Number = number; this.Goods = goods; this.Regulars = regulars; this.Bads = bads; }
static int GetClassPrior(INumber n) { if (n is NDouble) return 2; else if (n is NComplex) return 3; return -1; }
public void AssignNumber(INumber number) { if (this.Number != default(INumber)) { var errorMessage = string.Format("The number of Player {0} can't be changed once assigned", this.Information.Name); throw new ApplicationException(errorMessage); } this.Number = number; }
public IAttemptResult Compare(INumber mainNumber, INumber triedNumber) { var goodsCount = triedNumber.Units.Count(u => mainNumber.Units.Any(x => x.Equals(u))); var regularsCount = triedNumber.Units.Count(u => mainNumber.Units.Any(x => x.Position != u.Position && x.Value == u.Value)); return new AttemptResult { Number = triedNumber, Goods = goodsCount, Regulars = regularsCount, Bads = triedNumber.Units.Count() - goodsCount - regularsCount }; }
static INumber[] GetOps(INumber a, INumber b) { INumber op1, op2; if (GetClassPrior(a) > GetClassPrior(b)) { op1 = a; op2 = Conv(b, a); } else { op2 = b; op1 = Conv(a, b); } return new INumber[] { op1, op2 }; }
public INumber Build(INumber referenceNumber, int unitsToReplace, IEnumerable<INumberUnit> unitsToAdd) { var newNumber = (INumber)referenceNumber.Clone(); var random = new Random(); foreach (var unitToInclude in this.unitsToInclude) { newNumber.EditUnit(unitToInclude.Position, unitToInclude.Value); } var usedValues = new List<int>(); foreach (var unitToAdd in unitsToAdd) { usedValues.Add(newNumber.GetUnitValue(unitToAdd.Position)); newNumber.EditUnit(unitToAdd.Position, unitToAdd.Value); } var lockedPositions = unitsToAdd.Select(u => u.Position).ToList(); var originalLockedPositions = new List<int>(); originalLockedPositions.AddRange(lockedPositions); this.ReplaceUnits(newNumber, unitsToReplace, lockedPositions, usedValues, random); var unitsToShuffle = referenceNumber.Units.Count() - unitsToReplace - unitsToAdd.Count() - this.unitsToInclude.Count; if (unitsToShuffle > 0) { var positionsToShuffle = newNumber.Units .Where(u => !this.unitsToInclude.Select(x => x.Position).Any(p => p == u.Position)) .Where(u => !originalLockedPositions.Any(p => p == u.Position)) .Where(u => referenceNumber.Units.Any(x => x.Value == u.Value)) .Take(unitsToShuffle) .Select(u => u.Position) .ToList(); this.ShuffleUnits(newNumber, positionsToShuffle, originalLockedPositions, random); } return newNumber; }
static INumber Conv(INumber n, INumber nType) { if (nType is NComplex) { if (n is NDouble) { double re = ((NDouble)n)._value; return new NComplex(re, 0); } else return n; } else if (nType is NDouble) { return n; } throw new ArgumentException("wrong use of conv method for INumbers"); }
private int GetRandomNumberUnitValue(INumber number, IEnumerable<int> usedValues, Random random) { var reservedValues = this.unitsToInclude.Select(u => u.Value); var randomNumberUnitValue = random.Next(0, 10); if (number.HasUnitValue(randomNumberUnitValue) || usedValues.Any(v => v == randomNumberUnitValue) || reservedValues.Any(v => v == randomNumberUnitValue) || this.valuesToExclude.Any(v => v == randomNumberUnitValue)) { return this.GetRandomNumberUnitValue(number, usedValues, random); } return randomNumberUnitValue; }
bool Window.isNaN(INumber value) { return false; }
/// <summary> /// Put big double value -99999999.99 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutBigDoubleNegativeDecimal(this INumber operations, double numberBody) { operations.PutBigDoubleNegativeDecimalAsync(numberBody).GetAwaiter().GetResult(); }
/// <summary> /// Get big double value -99999999.99 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static double?GetBigDoubleNegativeDecimal(this INumber operations) { return(operations.GetBigDoubleNegativeDecimalAsync().GetAwaiter().GetResult()); }
/// <summary> /// Gets a value indicating whether or not the input is NaN. /// </summary> /// <param name="value">The input value.</param> /// <returns>True is the number is NaN, false otherwise.</returns> public static bool isNaN(INumber value) { return false; }
private void ShuffleUnits(INumber newNumber, IEnumerable<int> positionsToShuffle, IList<int> lockedPositions, Random random) { foreach (var positionToShuffle in positionsToShuffle) { var contextLockedPositions = new List<int>(); contextLockedPositions.AddRange(lockedPositions); contextLockedPositions.Add(positionToShuffle); var firstPositionToShuffle = positionToShuffle; var secondPositionToShuffle = this.GetRandomPosition(newNumber, contextLockedPositions, random, lockPosition: false); var firstValueToShuffle = newNumber.GetUnitValue(firstPositionToShuffle); var secondValueToShuffle = newNumber.GetUnitValue(secondPositionToShuffle); newNumber.EditUnit(firstPositionToShuffle, secondValueToShuffle); newNumber.EditUnit(secondPositionToShuffle, firstValueToShuffle); } }
/// <summary> /// Put small double value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutSmallDouble(this INumber operations, double numberBody) { operations.PutSmallDoubleAsync(numberBody).GetAwaiter().GetResult(); }
public INumber Substraction(INumber number) { var num = number as IntegerNumber; return(new IntegerNumber(this.number - num.number)); }
public INumber Sum(INumber arg) { return JNumberMath.Sum(this, arg); }
/// <summary> /// Get invalid double Number value /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static double?GetInvalidDouble(this INumber operations) { return(operations.GetInvalidDoubleAsync().GetAwaiter().GetResult()); }
//public RationalNumber DoRationalFromInteger() //{ // return new RationalNumber(this.number, 1); //} public INumber Adding(INumber number) { var num = number as IntegerNumber; return(new IntegerNumber(this.number + num.number)); }
/// <summary> /// Get small decimal value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static decimal?GetSmallDecimal(this INumber operations) { return(operations.GetSmallDecimalAsync().GetAwaiter().GetResult()); }
/// <summary> /// Put small decimal value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task PutSmallDecimalAsync(this INumber operations, decimal numberBody, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.PutSmallDecimalWithHttpMessagesAsync(numberBody, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Put small decimal value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutSmallDecimal(this INumber operations, decimal numberBody) { operations.PutSmallDecimalAsync(numberBody).GetAwaiter().GetResult(); }
private void ReplaceUnits(INumber newNumber, int unitsToReplace, Random random) { this.ReplaceUnits(newNumber, unitsToReplace, lockedPositions: new List<int>(), usedValues: new List<int>(), random: random); }
/// <summary> /// Converts the number to exponential form. /// </summary> /// <param name="value">The exponent power.</param> /// <returns>A text representation of the number.</returns> public string toExponential(INumber value) { return null; }
private void ReplaceUnits(INumber newNumber, IEnumerable<int> valuesToReplace, IList<int> lockedPositions, IList<int> usedValues, Random random) { var exceededUnits = (valuesToReplace.Count() + lockedPositions.Count + this.unitsToInclude.Count()) - newNumber.Units.Count(); if (exceededUnits > 0) { valuesToReplace = valuesToReplace.Take(valuesToReplace.Count() - exceededUnits); } foreach (var valueToReplace in valuesToReplace) { var unitToReplace = newNumber.Units.FirstOrDefault(u => u.Value == valueToReplace); if (unitToReplace == default(INumberUnit)) { continue; } if (lockedPositions.Contains(unitToReplace.Position) || this.unitsToInclude.Any(u => u.Position == unitToReplace.Position)) { continue; } var positionToReplace = unitToReplace.Position; var randomNumberUnitValue = this.GetRandomNumberUnitValue(newNumber, usedValues, random); usedValues.Add(valueToReplace); newNumber.EditUnit(positionToReplace, randomNumberUnitValue); } }
/// <summary> /// Get null Number value /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static double?GetNull(this INumber operations) { return(operations.GetNullAsync().GetAwaiter().GetResult()); }
public INumber Division(INumber number) { var num = number as IntegerNumber; return(new IntegerNumber(this.number / num.number)); }
/// <summary> /// Get big double value 3.402823e-20 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static double?GetSmallFloat(this INumber operations) { return(operations.GetSmallFloatAsync().GetAwaiter().GetResult()); }
public INumber Idiv(INumber arg) { return new NDouble(_value / ((NDouble)arg)._value); }
public INumber Multiplication(INumber number) { var num = number as IntegerNumber; return(new IntegerNumber(this.number * num.number)); }
/// <summary> /// Converts the number to a fixed precision form. /// </summary> /// <param name="value">The number of decimal places.</param> /// <returns>A text representation of the number.</returns> public string toPrecision(INumber value) { return null; }
public override bool CanJoin(RuntimeData runtime, INumber val) { throw new NotImplementedException(); }
public override bool Equals(RuntimeData runtime, INumber val) { return(false); }
public override bool Equals(RuntimeData runtime, INumber val) { return (val is IConstParameter && this.value == (val as IConstParameter).ConstValue); }
/// <summary> /// Gets a value indicating whether or not the input is a finite number. /// </summary> /// <param name="value">The input value.</param> /// <returns>True is the number is finite, false otherwise.</returns> public static bool isFinite(INumber value) { return false; }
private void OnNumberTypeChanged(DependencyPropertyChangedEventArgs e) { _number = NumberFactory.Create((NumberType)e.NewValue); _number.Initialize(Number, Minimum, Maximum, Step, DefaultNumber, InputCulture, PredefinesCulture); }
bool Window.isFinite(INumber value) { return false; }
/// <summary> /// Initializes a new instance of the <see cref="DW.WPFToolkit.Controls.NumberBox" /> class. /// </summary> public NumberBox() { _number = NumberFactory.Create(NumberType); }
/// <summary> /// Creates a new number. /// </summary> /// <param name="number">The numeric value.</param> public Number(INumber number) { }
public int SetNumber(INumber Number) { return(Number.Number * -1); }
private int GetRandomNumberUnitValue(INumber number, Random random) { return this.GetRandomNumberUnitValue(number, usedValues: new List<int>(), random: random); }
public void Process(INumber resultNumber) { WriteToConsole(resultNumber); }
private int GetRandomPosition(INumber number, IList<int> lockedPositions, Random random, bool lockPosition = true) { var reservedPositions = this.unitsToInclude.Select(u => u.Position); var randomPosition = number.Units .Select(u => u.Position) .Where(p => !lockedPositions.Contains(p)) .Where(p => !reservedPositions.Contains(p)) .First(); if (lockPosition) { lockedPositions.Add(randomPosition); } return randomPosition; }
/// <summary> /// Put big decimal value 99999999.99 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutBigDecimalPositiveDecimal(this INumber operations, decimal?numberBody) { Task.Factory.StartNew(s => ((INumber)s).PutBigDecimalPositiveDecimalAsync(numberBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private void ReplaceUnits(INumber newNumber, int unitsToReplace, IList<int> lockedPositions, IList<int> usedValues, Random random) { var exceededUnits = (unitsToReplace + lockedPositions.Count + this.unitsToInclude.Count()) - newNumber.Units.Count(); if (exceededUnits > 0) { unitsToReplace = unitsToReplace - exceededUnits; } for (var i = 0; i < unitsToReplace; i++) { var positionToReplace = this.GetRandomPosition(newNumber, lockedPositions, random); var randomNumberUnitValue = this.GetRandomNumberUnitValue(newNumber, usedValues, random); usedValues.Add(newNumber.GetUnitValue(positionToReplace)); newNumber.EditUnit(positionToReplace, randomNumberUnitValue); } }
/// <summary> /// Put big decimal value -99999999.99 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task PutBigDecimalNegativeDecimalAsync(this INumber operations, decimal?numberBody, CancellationToken cancellationToken = default(CancellationToken)) { await operations.PutBigDecimalNegativeDecimalWithHttpMessagesAsync(numberBody, null, cancellationToken).ConfigureAwait(false); }
private void ShuffleUnits(INumber newNumber, IEnumerable<int> positionsToShuffle, Random random) { this.ShuffleUnits(newNumber, positionsToShuffle, lockedPositions: new List<int>(), random: random); }
/// <summary> /// Get big decimal value -99999999.99 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static decimal?GetBigDecimalNegativeDecimal(this INumber operations) { return(Task.Factory.StartNew(s => ((INumber)s).GetBigDecimalNegativeDecimalAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public override bool CanJoin(RuntimeData runtime, INumber val) { return(false); }
/// <summary> /// Put small double value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutSmallDouble(this INumber operations, double?numberBody) { Task.Factory.StartNew(s => ((INumber)s).PutSmallDoubleAsync(numberBody), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
public INumber Mul(INumber arg) { return JNumberMath.Mul(this, arg); }
/// <summary> /// Put small double value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task PutSmallDoubleAsync(this INumber operations, double?numberBody, CancellationToken cancellationToken = default(CancellationToken)) { await operations.PutSmallDoubleWithHttpMessagesAsync(numberBody, null, cancellationToken).ConfigureAwait(false); }
public INumber Div(INumber arg) { return JNumberMath.Div(this, arg); }
/// <summary> /// Get big double value 2.5976931e-101 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> public static double?GetSmallDouble(this INumber operations) { return(Task.Factory.StartNew(s => ((INumber)s).GetSmallDoubleAsync(), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
public INumber Isum(INumber arg) { throw new NotImplementedException(); }
public BorderRadius(INumber all) : this(all, all) { }
/// <summary> /// Converts the number to a fixed form. /// </summary> /// <param name="value">The number of decimal places.</param> /// <returns>A text representation of the number.</returns> public string toFixed(INumber value) { return null; }
public static INumber Sum(INumber a, INumber b) { INumber[] ops = GetOps(a, b); return ops[0].Isum(ops[1]); }
public BorderRadius(INumber horizontal, INumber vertical) { Horizontal = horizontal; Vertical = vertical; }
/// <summary> /// Put big float value 3.402823e+20 /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='numberBody'> /// </param> public static void PutBigFloat(this INumber operations, double numberBody) { operations.PutBigFloatAsync(numberBody).GetAwaiter().GetResult(); }