Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 public AttemptResult(INumber number, int goods, int regulars, int bads)
 {
     this.Number = number;
     this.Goods = goods;
     this.Regulars = regulars;
     this.Bads = bads;
 }
Exemplo n.º 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
            };
        }
Exemplo n.º 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 };
        }
Exemplo n.º 7
0
        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;
        }
Exemplo n.º 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");
        }
Exemplo n.º 9
0
        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;
        }
Exemplo n.º 10
0
 bool Window.isNaN(INumber value)
 {
     return false;
 }
Exemplo n.º 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();
 }
Exemplo n.º 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());
 }
Exemplo n.º 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;
 }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 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();
 }
Exemplo n.º 16
0
        public INumber Substraction(INumber number)
        {
            var num = number as IntegerNumber;

            return(new IntegerNumber(this.number - num.number));
        }
Exemplo n.º 17
0
 public INumber Sum(INumber arg)
 {
     return JNumberMath.Sum(this, arg);
 }
Exemplo n.º 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());
 }
Exemplo n.º 19
0
        //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));
        }
Exemplo n.º 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());
 }
Exemplo n.º 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();
 }
Exemplo n.º 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();
 }
Exemplo n.º 23
0
 private void ReplaceUnits(INumber newNumber, int unitsToReplace, Random random)
 {
     this.ReplaceUnits(newNumber, unitsToReplace, lockedPositions: new List<int>(), usedValues: new List<int>(), random: random);
 }
Exemplo n.º 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; }
Exemplo n.º 25
0
        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);
            }
        }
Exemplo n.º 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());
 }
Exemplo n.º 27
0
        public INumber Division(INumber number)
        {
            var num = number as IntegerNumber;

            return(new IntegerNumber(this.number / num.number));
        }
Exemplo n.º 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());
 }
Exemplo n.º 29
0
 public INumber Idiv(INumber arg)
 {
     return new NDouble(_value / ((NDouble)arg)._value);
 }
Exemplo n.º 30
0
        public INumber Multiplication(INumber number)
        {
            var num = number as IntegerNumber;

            return(new IntegerNumber(this.number * num.number));
        }
Exemplo n.º 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; }
Exemplo n.º 32
0
 public override bool CanJoin(RuntimeData runtime, INumber val)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 33
0
 public override bool Equals(RuntimeData runtime, INumber val)
 {
     return(false);
 }
Exemplo n.º 34
0
 public override bool Equals(RuntimeData runtime, INumber val)
 {
     return
         (val is IConstParameter && this.value == (val as IConstParameter).ConstValue);
 }
Exemplo n.º 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;
 }
Exemplo n.º 36
0
 private void OnNumberTypeChanged(DependencyPropertyChangedEventArgs e)
 {
     _number = NumberFactory.Create((NumberType)e.NewValue);
     _number.Initialize(Number, Minimum, Maximum, Step, DefaultNumber, InputCulture, PredefinesCulture);
 }
Exemplo n.º 37
0
 bool Window.isFinite(INumber value)
 {
     return false;
 }
Exemplo n.º 38
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DW.WPFToolkit.Controls.NumberBox" /> class.
 /// </summary>
 public NumberBox()
 {
     _number = NumberFactory.Create(NumberType);
 }
Exemplo n.º 39
0
		/// <summary>
		/// Creates a new number.
		/// </summary>
		/// <param name="number">The numeric value.</param>
		public Number(INumber number) { }
Exemplo n.º 40
0
 public int SetNumber(INumber Number)
 {
     return(Number.Number * -1);
 }
Exemplo n.º 41
0
 private int GetRandomNumberUnitValue(INumber number, Random random)
 {
     return this.GetRandomNumberUnitValue(number, usedValues: new List<int>(), random: random);
 }
Exemplo n.º 42
0
 public void Process(INumber resultNumber)
 {
     WriteToConsole(resultNumber);
 }
Exemplo n.º 43
0
        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;
        }
Exemplo n.º 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();
 }
Exemplo n.º 45
0
        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);
            }
        }
Exemplo n.º 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);
 }
Exemplo n.º 47
0
 private void ShuffleUnits(INumber newNumber, IEnumerable<int> positionsToShuffle, Random random)
 {
     this.ShuffleUnits(newNumber, positionsToShuffle, lockedPositions: new List<int>(), random: random);
 }
Exemplo n.º 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());
 }
Exemplo n.º 49
0
 public override bool CanJoin(RuntimeData runtime, INumber val)
 {
     return(false);
 }
Exemplo n.º 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();
 }
Exemplo n.º 51
0
 public INumber Mul(INumber arg)
 {
     return JNumberMath.Mul(this, arg);
 }
Exemplo n.º 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);
 }
Exemplo n.º 53
0
 public INumber Div(INumber arg)
 {
     return JNumberMath.Div(this, arg);
 }
Exemplo n.º 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());
 }
Exemplo n.º 55
0
 public INumber Isum(INumber arg)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 56
0
 public BorderRadius(INumber all) : this(all, all)
 {
 }
Exemplo n.º 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; }
Exemplo n.º 58
0
 public static INumber Sum(INumber a, INumber b)
 {
     INumber[] ops = GetOps(a, b);
     return ops[0].Isum(ops[1]);
 }
Exemplo n.º 59
0
 public BorderRadius(INumber horizontal, INumber vertical)
 {
     Horizontal = horizontal;
     Vertical   = vertical;
 }
Exemplo n.º 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();
 }