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;
 }
Beispiel #3
0
 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
            };
        }
Beispiel #6
0
        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;
        }
Beispiel #8
0
        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;
        }
Beispiel #10
0
 bool Window.isNaN(INumber value)
 {
     return false;
 }
Beispiel #11
0
 /// <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();
 }
Beispiel #12
0
 /// <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());
 }
Beispiel #13
0
 /// <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);
            }
        }
Beispiel #15
0
 /// <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));
        }
Beispiel #17
0
 public INumber Sum(INumber arg)
 {
     return JNumberMath.Sum(this, arg);
 }
Beispiel #18
0
 /// <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));
        }
Beispiel #20
0
 /// <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());
 }
Beispiel #21
0
 /// <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();
 }
Beispiel #22
0
 /// <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);
 }
Beispiel #24
0
		/// <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);
            }
        }
Beispiel #26
0
 /// <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));
        }
Beispiel #28
0
 /// <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());
 }
Beispiel #29
0
 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));
        }
Beispiel #31
0
		/// <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; }
Beispiel #32
0
 public override bool CanJoin(RuntimeData runtime, INumber val)
 {
     throw new NotImplementedException();
 }
Beispiel #33
0
 public override bool Equals(RuntimeData runtime, INumber val)
 {
     return(false);
 }
Beispiel #34
0
 public override bool Equals(RuntimeData runtime, INumber val)
 {
     return
         (val is IConstParameter && this.value == (val as IConstParameter).ConstValue);
 }
Beispiel #35
0
 /// <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);
 }
Beispiel #37
0
 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);
 }
Beispiel #39
0
		/// <summary>
		/// Creates a new number.
		/// </summary>
		/// <param name="number">The numeric value.</param>
		public Number(INumber number) { }
Beispiel #40
0
 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);
 }
Beispiel #42
0
 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;
        }
Beispiel #44
0
 /// <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);
            }
        }
Beispiel #46
0
 /// <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);
 }
Beispiel #48
0
 /// <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());
 }
Beispiel #49
0
 public override bool CanJoin(RuntimeData runtime, INumber val)
 {
     return(false);
 }
Beispiel #50
0
 /// <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();
 }
Beispiel #51
0
 public INumber Mul(INumber arg)
 {
     return JNumberMath.Mul(this, arg);
 }
Beispiel #52
0
 /// <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);
 }
Beispiel #53
0
 public INumber Div(INumber arg)
 {
     return JNumberMath.Div(this, arg);
 }
Beispiel #54
0
 /// <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());
 }
Beispiel #55
0
 public INumber Isum(INumber arg)
 {
     throw new NotImplementedException();
 }
Beispiel #56
0
 public BorderRadius(INumber all) : this(all, all)
 {
 }
Beispiel #57
0
		/// <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; }
Beispiel #58
0
 public static INumber Sum(INumber a, INumber b)
 {
     INumber[] ops = GetOps(a, b);
     return ops[0].Isum(ops[1]);
 }
Beispiel #59
0
 public BorderRadius(INumber horizontal, INumber vertical)
 {
     Horizontal = horizontal;
     Vertical   = vertical;
 }
Beispiel #60
0
 /// <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();
 }