Beispiel #1
0
        public Card(int i, Fraction f)
        {

            int n;
            if (f == Fraction.Dragon)
            {
                n = Card.dragonCards;
                action1 = dragonActionsDictionary[i][0];
                if (dragonActionsDictionary[i].Count > 1)
                    action2 = dragonActionsDictionary[i][1];
                else action2 = action1;
            }
            else
            {
                n = Card.dwarfCards;
                action1 = dwarfsActionsDictionary[i][0];
                if (dwarfsActionsDictionary[i].Count > 1)
                    action2 = dwarfsActionsDictionary[i][1];
                else action2 = action1;
            }
                
                
            if (i > 0 && i <= n)
            {
                id = i;
                fraction = f;
                string c;                
                if (fraction == Fraction.Dwarf)               
                    c = "K";               
                    else
                    c = "D";
                src = "Images/Cards/" + c + id.ToString()+".png";
            }
        }      
Beispiel #2
0
        public long Solve()
        {
            var indexes = new int[Limit];

            var value = 2;

            for (var i = 0; i < Limit; i++)
            {
                if (((i - 1) % 3) != 0)
                {
                    indexes[i] = 1;
                }
                else
                {
                    indexes[i] = value;
                    value = 2 + value;
                }
            }

            var fractal = new Fraction(1, indexes[Limit - 1]); // 1/ cislo
            for (var i = Limit - 2; i >= 0; i--)
            {
                fractal.Update(indexes[i]);

                Console.WriteLine("{0} / {1}", fractal.TopPart, fractal.DownPart);
            }

            var result = fractal.TopPart + (fractal.DownPart * 2);

            Console.WriteLine("{0} / {1}", fractal.TopPart + (fractal.DownPart * 2), fractal.DownPart);

            return (long)SumOfDigits(result);
        }
        public decimal SubtractFraction(Fraction firstFraction, Fraction secondFraction)
        {
            newFraction.Numerator = firstFraction.Numerator * secondFraction.Denominator - secondFraction.Numerator * firstFraction.Denominator;
            newFraction.Denominator = firstFraction.Denominator * secondFraction.Denominator;

            return Math.Round(Decimal.Divide(newFraction.Numerator,newFraction.Denominator), 2, MidpointRounding.AwayFromZero);
        }
 static void Create(Fraction f)
 {
     FractionInfo i = new FractionInfo();
     switch (f) {
         case Fraction.Humans:
             i.name="Human Alliance";
             i.emblem = "/Humans/Emblem.gif";
             i.smallEmblem = "/Humans/SmallEmblem.gif";
             break;
         case Fraction.Orcs:
             i.name = "Horde";
             i.emblem = "/Orcs/Emblem.gif";
             i.smallEmblem = "/Orcs/SmallEmblem.gif";
             break;
         case Fraction.NightElves:
             i.name = "Night Elves";
             i.emblem = "/NightElves/Emblem.gif";
             i.smallEmblem = "/NightElves/SmallEmblem.gif";
             break;
         case Fraction.Undead:
             i.name = "Undead Scourge";
             i.emblem = "/Undead/Emblem.gif";
             i.smallEmblem = "/Undead/SmallEmblem.gif";
             break;
         case Fraction.Neutrals:
             i.name = "Creeps";
             i.emblem = "";
             i.smallEmblem = "";
             break;
     }
     infos[f] = i;
 }
        public void ComplexFractionConstructor()
        {
            var complex1 = new Fraction(new Fraction(3, 2), new Fraction(2, 5));
            var complex2 = new Fraction(3, 2)/new Fraction(2, 5);

            Assert.IsTrue(complex1 == complex2);
        }
 static void Main()
 {
     Fraction temp = new Fraction(1, 1);
     temp = temp + new Fraction(5, 2);
     temp = temp - new Fraction(8, 2);
     Console.WriteLine(temp);
 }
    static void Main()
    {
        Console.WriteLine("Enter fraction");
        string input = Console.ReadLine();
        Fraction fraction = new Fraction();
        fraction = fraction.Parce(input);
        fraction.CalculateFractionValue();
        Console.WriteLine("Decimal value of the fraction is:");
        Console.WriteLine(fraction.FractionValue);
        fraction.Cut();
        Console.WriteLine("Fraction after cut is:");
        Console.WriteLine(fraction.ToString());
        Console.WriteLine("Decimal value of the cut fraction is:");
        Console.WriteLine(fraction.FractionValue);

        Console.WriteLine("Enter numerator");
        int numerator = int.Parse(Console.ReadLine());
        Console.WriteLine("Enter denumerator");
        int denumerator = int.Parse(Console.ReadLine());
        Fraction otherFraction = new Fraction(numerator, denumerator);
        Console.WriteLine("Fraction is:");
        Console.WriteLine(otherFraction.ToString());
        otherFraction.CalculateFractionValue();
        Console.WriteLine("Decimal value of the fraction is:");
        Console.WriteLine(otherFraction.FractionValue);
        otherFraction.Cut();
        Console.WriteLine("Fraction after cut is:");
        Console.WriteLine(otherFraction.ToString());
        Console.WriteLine("Decimal value of the cut fraction is:");
        Console.WriteLine(otherFraction.FractionValue);
    }
Beispiel #8
0
    static void Main()
    {
        try
        {
            Fraction fraction1 = new Fraction();
            Fraction fraction2 = new Fraction();

            Console.WriteLine("Please enter fraction1 numerator: ");
            fraction1.Numerator = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter fraction2 numerator: ");
            fraction1.Denominator = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter fraction1 denominator: ");
            fraction2.Numerator = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter fraction2 denominator: ");
            fraction2.Denominator = int.Parse(Console.ReadLine());

            Fraction additionResult = fraction1 + fraction2;
            Fraction substractionResult = fraction1 - fraction2;

            Console.WriteLine(additionResult.Numerator);
            Console.WriteLine(additionResult.Denominator);
            Console.WriteLine(additionResult);
            Console.WriteLine(substractionResult);
        }
        catch (ArgumentException aex)
        {
            Console.WriteLine(aex.Message);
        }
        catch (Exception ex)
        {
            Console.WriteLine("Invalid number! " + ex.Message);
        }
    }
Beispiel #9
0
 public Segment (Point sp, Point ep, Fraction segmentSlope)
 {
   StartPoint = sp;
   EndPoint = ep;
   
   Slope = segmentSlope;
 }
 static void Main()
 {
     Fraction a = new Fraction(1, 2);
         Fraction b = new Fraction(3, 7);
         Fraction c = new Fraction(2, 3);
         Console.WriteLine((double)(a * b + c));
 }
 public void NextChallenge(Fraction[] fractions, Fraction fraction)
 {
     tryBtn.enabled = false;
     Views.TogglesEnabled(pizzas, true);
     SetFraction(fraction);
     SetPizzas(fractions);
 }
 public void RemoveDigit()
 {
     Fraction f = new Fraction(13, 43);
     Fraction newf = f.RemoveDigit('3');
     Assert.AreEqual(1, newf.Nominator);
     Assert.AreEqual(4, newf.Denominator);
 }
        public GameMultiplayerControl(Control Control, GameScreen GameScreen, int MapIndex, int SaveGameIndex, MultiplayerMatchStartInformation MP)
            : base(Control, GameScreen, MapIndex, SaveGameIndex, true)
        {
            this.UserName = MP.UserName;
            this.Password = MP.Password;
            this.MatchId = MP.MatchId;
            this.GameState = 0;
            this.MultiplayerMatch = true;
            this.MultiplayerFraction = MP.MultiplayerFraction;

            // timer checking if a newer game state is available
            NewGameStateAvailableTimer = new System.Windows.Forms.Timer();
            NewGameStateAvailableTimer.Interval = 1000;
            NewGameStateAvailableTimer.Tick += UpdateGameState;
            NewGameStateAvailableTimer.Start();

            // show multiplayer tab (gui) and update it's content
            GameScreen.TabItem_Multiplayer.Visibility = Visibility.Visible;
            GameScreen.Button_Restart.IsEnabled = false; // disable restart map button for multiplayer matches
            GameScreen.Label_Multiplayer_MatchID.Content = R.String("MatchID") + ": " + MatchId.ToString();
            GameScreen.Label_Multiplayer_MatchVersion.Content = R.String("MatchVersion") + ": " + GameState.ToString();

            // background worker
            BackgroundWorkerDownloadLatestGameState.DoWork += BackgroundWorkerDownloadLatestGameStateWork;
            BackgroundWorkerDownloadLatestGameState.RunWorkerCompleted += BackgroundWorkerDownloadLatestGameState_RunWorkerCompleted;
        }
Beispiel #14
0
 public static void PizzaResourceToImages(Fraction fraction, Image[] images)
 {
     foreach (Image image in images)
     {
         PizzaResourceToImage(fraction, image);
     }
 }
Beispiel #15
0
Datei: Q4.cs Projekt: Tilps/Stash
 static Fraction Abs(Fraction input)
 {
     if (input.Denominator > 0 && input.Numerator >= 0)
         return input;
     if (input.Denominator < 0 && input.Numerator <= 0)
         return input;
     return new Fraction(-input.Numerator, input.Denominator);
 }
 public bool IsCorrect(List<int> selected)
 {
     Fraction f = new Fraction(0, 1);
     foreach(int s in selected) {
         f += allFractions[s];
     }
     return fraction.Equals(f);
 }
Beispiel #17
0
 static void Main()
 {
     var a = new Fraction(1, 1);
     var b = new Fraction(1, -4);
     var c = a + b;
     Console.WriteLine(c.Print());
     Console.WriteLine(c);
 }
Beispiel #18
0
 public Event(EventType type, Fraction time, int car1, int car2)
     : this()
 {
     Type = type;
     Time = time;
     Car1 = car1;
     Car2 = car2;
 }
 public static FractionInfo Get(Fraction f)
 {
     if (infos == null)
         infos = new SortedDictionary<Fraction, FractionInfo>();
     if (!infos.ContainsKey(f))
         Create(f);
     return infos[f];
 }
Beispiel #20
0
 public static bool HaveEqualDenominator(Fraction[] fractions)
 {
     if(fractions.Length != 0) {
         int denom = fractions[0].Denominator;
         foreach(Fraction fraction in fractions) if(!fraction.Denominator.Equals(denom)) return false;
     }
     return true;
 }
Beispiel #21
0
 public static Fraction[] GetRandomForDenominator(int denom, int quantity)
 {
     Fraction[] fractions = new Fraction[quantity];
     Randomizer numeratorRandomizer = Randomizer.New(denom);
     for(int i = 0; i < quantity; i++)
         fractions[i] = new Fraction(numeratorRandomizer.Next(), denom);
     return fractions;
 }
Beispiel #22
0
        public void Power_Fraction_IntegerExponent(int x, int n, int d)
        {
            var a = new Fraction(n, d);
            var pow = a.Power(x);
            var exp = Math.Pow((double)n / (double)d, x);

            Assert.That(Math.Round(pow.Value, 8), Is.EqualTo(Math.Round(exp, 8)));
        }
Beispiel #23
0
 public Segment (Point sp, Point ep)
 {
   StartPoint = sp;
   EndPoint = ep;
   
   //Calculate the slope
   Slope = new Fraction(ep.y - sp.y, ep.x - sp.x);
 }
 int[] GetAnsweredArray(Fraction[] ordered)
 {
     int[] result = new int[ordered.Length];
     for(int i = 0; i < ordered.Length; i++) {
         result[i] = Array.IndexOf(ordered, allFractions[i]) + 1;
     }
     return result;
 }
Beispiel #25
0
public static void Main()
{
Fraction f = new Fraction();
f.Nominator = 10;
f.Denominator = 20;
Console.WriteLine(f.Nominator);
Console.WriteLine(f.Denominator);
}
 public NpcState(Npc Npc, MapState MapState, Script AI, Fraction Fraction, MapPoint Position)
     : base(Npc)
 {
     this.MapState = MapState;
     //this.MapActiveObjectGuid = this.MapState.AddActiveObject(this.Npc.MapActiveObject, Position);
     this.AI = AI;
     this.Fraction = Fraction;
 }
        public void ComplexFractionTest()
        {
            // basic definition of a complex fraction
            Fraction complex1 = new Fraction(new Fraction(3, 2), new Fraction(2, 5));
            Fraction complex2 = new Fraction("3/4","2/6");

            // but under the hood, we are actually doing following
            Fraction complex3 = new Fraction(3, 2) / new Fraction(2, 5);
        }
 /// <summary>
 /// 将分母的负号移到分子
 /// </summary>
 /// <param name="f">要操作的分数</param>
 public static Fraction MoveMinusToNumerator(Fraction f)
 {
   if (f.Numerator != 0 && f.Denominator < 0)
   {
     f.Numerator = -f.Numerator;
     f.Denominator = -f.Denominator;
   }
   return f;
 }
Beispiel #29
0
 static void Main(string[] args)
 {
     Fraction fraction1 = new Fraction(22, 7);
     Fraction fraction2 = new Fraction(40, 4);
     Fraction result = fraction1 + fraction2;
     Console.WriteLine(result.Numerator);
     Console.WriteLine(result.Denominator);
     Console.WriteLine(result);
 }
 static void Main()
 {
     Fraction fraction1 = new Fraction(23, 67);
     Fraction fraction2 = new Fraction(40, 4);
     Fraction result = fraction1 - fraction2;
     Console.WriteLine(result.Numerator);
     Console.WriteLine(result.Denominator);
     Console.WriteLine(result);
 }
 public TimeScaleAttribute(double scale = 1)
 {
     Scale = Fraction.FromDoubleRounded(scale);
 }
        static void Main(string[] args)
        {
            Fraction frac = new Fraction();

            Console.Write("Please enter a Decimal number: ");
            string temp = Console.ReadLine();

            if (!decimal.TryParse(temp, out decimal dec))
            {
                Console.WriteLine("Sorry, we didn't recogize your entry");
            }
            else
            {
                frac.DecimalValue = dec;
                Console.WriteLine("Here's your entry as a fraction: " + frac.ToString());
            }
            Console.WriteLine("Below, we demonstrate the interaction between Double and Fraction:");
            frac.SetTo(1, 2);
            Console.WriteLine(frac.DoubleValue.ToString());

            frac.SetTo(1, 3);
            Console.WriteLine(frac.DoubleValue.ToString());

            double d = double.Parse("5.15151515151515E+297");

            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            d = double.Parse("-5.15151515151515E+297");;
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            d = double.Parse("5.15151515151515E-301");
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            d = double.Parse("-5.15151515151515E-301");
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            d = double.MaxValue;
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());


            d = double.MinValue;
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            d = double.Epsilon;
            frac.DoubleValue = d;
            Console.WriteLine(d.ToString() + "\t" + frac.DoubleValue.ToString());

            Console.WriteLine("Below, we demonstrate various operations on fractions:");

            Fraction f1 = new Fraction(2, 3);
            Fraction f2 = new Fraction(3, 5);

            Console.WriteLine(f1.ToString() + " + " + f2.ToString() + " = " + (f1 + f2).ToString());
            Console.WriteLine(f1.ToString() + " - " + f2.ToString() + " = " + (f1 - f2).ToString());
            Console.WriteLine(f1.ToString() + " * " + f2.ToString() + " = " + (f1 * f2).ToString());
            Console.WriteLine(f1.ToString() + " / " + f2.ToString() + " = " + (f1 / f2).ToString());
            Console.WriteLine(f1.ToString() + " < " + f2.ToString() + " = " + (f1 < f2).ToString());
            Console.WriteLine(f1.ToString() + " > " + f2.ToString() + " = " + (f1 > f2).ToString());
            Console.WriteLine(f1.ToString() + " <= " + f2.ToString() + " = " + (f1 <= f2).ToString());
            Console.WriteLine(f1.ToString() + " >= " + f2.ToString() + " = " + (f1 >= f2).ToString());

            Console.ReadLine();
        }
 public Fraction Divide(Fraction fraction1, Fraction fraction2)
 {
     return(new Fraction((fraction1.Numerator * fraction2.Denominator), (fraction2.Numerator * fraction1.Denominator)));
 }
Beispiel #34
0
        public void Division()
        {
            var x = new Fraction(3, 5);

            Assert.Equal(new Fraction(3, 2), x.Divide(new Fraction(2, 5)));
        }
 protected override bool ShouldRecieveStateData(Fraction f, Cannon c) => false;
 protected override bool ShouldRecieveData(Fraction f, Cannon c) => !f.IsNeutral && f != Screen.LocalPlayerFraction && !Screen.HasFinished;
Beispiel #37
0
 public override AbstractFractionController CreateNeutralController(GDGameScreen screen, Fraction fraction)
 {
     return(new EmptyController(screen, this, fraction));
 }
 public override Fraction GetModifiedFraction(Fraction original)
 {
     return(modifyOp(original));
 }
Beispiel #39
0
 /// <summary>
 /// Method that gets the root of quadratic equation provided as an argument
 /// if applicable
 /// </summary>
 /// <param name="eq">
 /// quadratic equation
 /// </param>
 public static void SolveExp(string eq)
 {
     if (eq == "")
     {
         Console.WriteLine("No Input Given.");
     }
     else
     {
         int    first   = 0;
         int    second  = 0;
         int    third   = 0;
         string currInt = "";
         bool   isHat   = false;
         for (int i = 0; i < eq.Length; ++i)
         {
             if (eq[i] == '^')
             {
                 isHat = true;
             }
             if (isHat)
             {
                 isHat = false;
             }
             else if (eq[i] == '1' || eq[i] == '2' || eq[i] == '3' || eq[i] == '4' || eq[i] == '5' || eq[i] == '6' || eq[i] == '7' || eq[i] == '8' || eq[i] == '9' || eq[i] == '-')
             {
                 if (i == eq.Length - 1)
                 {
                     currInt += eq[i];
                     if (first == 0)
                     {
                         first   = Convert.ToInt32(currInt);
                         currInt = "";
                     }
                     else
                     {
                         third   = Convert.ToInt32(currInt);
                         currInt = "";
                     }
                 }
                 else
                 {
                     currInt += eq[i];
                 }
             }
             else
             {
                 if (currInt == "")
                 {
                     if (first == 0)
                     {
                         first = 1;
                     }
                     else if (second == 0)
                     {
                         second = 1;
                     }
                     else
                     {
                         third = 1;
                     }
                 }
                 else
                 {
                     if (first == 0)
                     {
                         first   = Convert.ToInt32(currInt);
                         currInt = "";
                     }
                     else if (second == 0)
                     {
                         second  = Convert.ToInt32(currInt);
                         currInt = "";
                     }
                     else
                     {
                         third   = Convert.ToInt32(currInt);
                         currInt = "";
                     }
                 }
             }
         }
         var discriminant = second * second - 4 * first * third;
         if (discriminant < 0)
         {
             Console.WriteLine("No Root Exists.");
         }
         else
         {
             Root     currRoots = quad_form(first, second, third, discriminant);
             Fraction f         = GetFrac(currRoots.Root1, 0.001);
             Fraction f2        = GetFrac(currRoots.Root2, 0.001);
             Console.WriteLine("x = " + currRoots.Root1.ToString() + ", x = " + currRoots.Root2.ToString());
             string factoredExp = String.Empty;
             if (f.N < 0 && f2.N < 0)
             {
                 if (f.D == 1 && f2.D == 1)
                 {
                     int numerator  = -1 * f.N;
                     int numerator2 = -1 * f2.N;
                     factoredExp = "(x+" + numerator.ToString() + ")(x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f.D == 1)
                 {
                     int numerator1   = -1 * f.N;
                     int denominator2 = f2.D;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(x+" + numerator1.ToString() + ")(" + denominator2.ToString() + "x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f2.D == 1)
                 {
                     int denominator1 = f.D;
                     int numerator1   = -1 * f.N;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x+" + numerator1.ToString() + ")(x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else
                 {
                     int denominator1 = f.D;
                     int numerator1   = -1 * f.N;
                     int denominator2 = f2.D;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x+" + numerator1.ToString() + ")(" + denominator2.ToString() + "x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
             }
             else if (f.N < 0)
             {
                 if (f.D == 1 && f2.D == 1)
                 {
                     int numerator1 = -1 * f.N;
                     int numerator2 = f2.N;
                     factoredExp = "(x+" + numerator1.ToString() + ")(x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f.D == 1)
                 {
                     int numerator1   = -1 * f.N;
                     int denominator2 = f2.D;
                     int numerator2   = f2.N;
                     factoredExp = "(x+" + numerator1.ToString() + ")(" + denominator2.ToString() + "x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f2.D == 1)
                 {
                     int denominator1 = f.D;
                     int numerator1   = -1 * f.N;
                     int numerator2   = f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x+" + numerator1.ToString() + ")(x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else
                 {
                     int denominator1 = f.D;
                     int numerator1   = -1 * f.N;
                     int denominator2 = f2.D;
                     int numerator2   = f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x+" + numerator1.ToString() + ")(" + denominator2.ToString() + "x-" + numerator2.ToString();
                     Console.WriteLine(factoredExp);
                 }
             }
             else if (f2.N < 0)
             {
                 if (f.D == 1 && f2.D == 1)
                 {
                     int numerator1 = f.N;
                     int numerator2 = -1 * f2.N;
                     factoredExp = "(x-" + numerator1.ToString() + ")(x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f.D == 1)
                 {
                     int numerator1   = f.N;
                     int denominator2 = f2.D;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(x-" + numerator1.ToString() + ")(" + denominator2.ToString() + "x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f2.D == 1)
                 {
                     int denominator1 = f.D;
                     int numerator1   = f.N;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x-" + numerator1.ToString() + ")(x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else
                 {
                     int denominator1 = f.D;
                     int numerator1   = f.N;
                     int denominator2 = f2.D;
                     int numerator2   = -1 * f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x-" + numerator1.ToString() + ")(" + denominator2.ToString() + "x+" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
             }
             else
             {
                 if (f.D == 1 && f2.D == 1)
                 {
                     int numerator1 = f.N;
                     int numerator2 = f2.N;
                     factoredExp = "(x-" + numerator1.ToString() + ")(x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f.D == 1)
                 {
                     int numerator1   = f.N;
                     int denominator2 = f2.D;
                     int numerator2   = f2.N;
                     factoredExp = "(x-" + numerator1.ToString() + ")(" + denominator2.ToString() + "x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else if (f2.D == 1)
                 {
                     int denominator1 = f.D;
                     int numerator1   = f.N;
                     int numerator2   = f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x-" + numerator1.ToString() + ")(x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
                 else
                 {
                     int denominator1 = f.D;
                     int numerator1   = f.N;
                     int denominator2 = f2.D;
                     int numerator2   = f2.N;
                     factoredExp = "(" + denominator1.ToString() + "x-" + numerator1.ToString() + ")(" + denominator2.ToString() + "x-" + numerator2.ToString() + ")";
                     Console.WriteLine(factoredExp);
                 }
             }
         }
     }
 }
 public override string GetEquation(Fraction original)
 {
     return(original + " " + currentEquation + " = " + GetModifiedFraction(original));
 }
 public TimeScaleAttribute(int numerator = 1, int denominator = 1)
 {
     Scale = new Fraction(numerator, denominator);
 }
 public void SetHoopFraction(Fraction f)
 {
     //		// commented Debug.Log ("yea?");
     frac = f;
     SetHoopText();
 }
Beispiel #43
0
 public override KIController CreateKIController(GDGameScreen screen, Fraction fraction)
 {
     return(new LaserKIController(screen, this, fraction));
 }
Beispiel #44
0
        // Convert Metric offsets to Linear offsets for the entry list.
        public void CalculateLinearOffsets()
        {
            // verify all required metric info is present
            foreach (Entry entry in entries)
            {
                if (!entry.MetricOffsetInitialized)
                {
                    throw new Exception("Linear offsets can't be calculated because at least one entry is missing Metric offset information.");
                }
            }

            // delete all linear offset data
            ClearLinearOffsets();

            // make sure everything is sorted before we begin
            entries.Sort();

            // initialization
            Fraction baseLinear  = new Fraction(0, 1);
            Fraction bpm         = DefaultBPM;
            Fraction lastMetric  = new Fraction(0, 1);
            Fraction length      = new Fraction(0, 1);
            int      measure     = -1;
            Fraction measureRate = new Fraction(0, 1);
            Fraction rate        = new Fraction(0, 1);

            // BPM into seconds per measure
            measureRate = Util.CalculateMeasureRate(bpm);

            foreach (Entry entry in entries)
            {
                // on measures, update rate information
                if (entry.Type == EntryType.Measure)
                {
                    baseLinear += rate;
                    measure     = entry.MetricMeasure;

                    if (lengths.ContainsKey(measure))
                    {
                        length = lengths[measure];
                        rate   = length * measureRate;
                    }
                    else
                    {
                        length = new Fraction(1, 1);
                        rate   = measureRate;
                    }
                    lastMetric = new Fraction(0, 1);
                }

                // calculate linear offset
                Fraction entryOffset = entry.MetricOffset;
                entryOffset       -= lastMetric;
                entryOffset       *= rate;
                entryOffset       += baseLinear;
                entry.LinearOffset = entryOffset;

                // on tempo change, update rate information
                if (entry.Type == EntryType.Tempo)
                {
                    measureRate = Util.CalculateMeasureRate(bpm);
                    rate        = length * measureRate;
                    lastMetric  = entry.MetricOffset;
                }
            }
        }
Beispiel #45
0
 public override void SetFractionAndHealth(Fraction fraction, float hp)
 {
     SetFraction(fraction);
     CannonHealth.Set(hp);
     CannonHealth.Limit(0f, 1f);
 }
Beispiel #46
0
        // Convert Linear offsets into Metric offsets for the entry list.
        public void CalculateMetricOffsets()
        {
            // verify all required linear info is present
            foreach (Entry entry in entries)
            {
                if (!entry.LinearOffsetInitialized)
                {
                    throw new Exception("Metric offsets can't be calculated because at least one entry is missing Linear offset information.");
                }
            }

            // delete all metric offset data
            ClearMetricOffsets();

            // make sure everything is sorted before we begin
            entries.Sort();

            // initialization
            Fraction bpm = DefaultBPM;
            Fraction lastMeasureOffset            = new Fraction(0, 1);
            Fraction lastTempoOffset              = new Fraction(0, 1);
            Fraction length                       = new Fraction(0, 1);
            Dictionary <int, Fraction> lengthList = new Dictionary <int, Fraction>();
            int      measure                      = 0;
            Fraction measureLength                = new Fraction(0, 1);
            Fraction metricBase                   = new Fraction(0, 1);
            Fraction rate         = Util.CalculateMeasureRate(bpm);
            bool     tempoChanged = false;

            // discard length list since it will be generated later
            lengths.Clear();

            // get measure lengths for non-tempo-changing measures
            foreach (Entry entry in entries)
            {
                if (entry.Type == EntryType.Measure || entry.Type == EntryType.EndOfSong)
                {
                    if (entry.LinearOffset != lastMeasureOffset)
                    {
                        if (!tempoChanged)
                        {
                            Fraction distance = entry.LinearOffset - lastMeasureOffset;
                            if ((double)distance < 0)
                            {
                                throw new Exception("INTERNAL ERROR DAMMIT.");
                            }
                            lengthList.Add(measure, distance);
                        }
                        lastMeasureOffset = entry.LinearOffset;
                        measure++;
                        tempoChanged = false;
                    }
                }
                else if (entry.Type == EntryType.Tempo)
                {
                    if ((entry.LinearOffset - lastMeasureOffset).Numerator != 0)
                    {
                        tempoChanged = true;
                    }
                }
            }

            // initialization for the calculation phase
            measure           = 0;
            lastMeasureOffset = new Fraction(0, 1);

            Fraction tickMeasureLength;

            if (lengthList.ContainsKey(0))
            {
                tickMeasureLength = lengthList[0];
            }
            else
            {
                tickMeasureLength = new Fraction(0, 1);
            }

            List <Entry> entryList        = new List <Entry>();
            List <Entry> measureEntryList = new List <Entry>();

            // calculate metric offsets
            foreach (Entry entry in entries)
            {
                // on any measure, end of song or tempo events, update the metric rate information
                if (entry.Type == EntryType.Measure || entry.Type == EntryType.Tempo || entry.Type == EntryType.EndOfSong)
                {
                    Fraction measureDistance = ((entry.LinearOffset - lastTempoOffset) * TickRate) / rate;

                    // calculate metric offset for entries in tempo-changing measures
                    foreach (Entry tempoEntry in entryList)
                    {
                        tempoEntry.MetricOffset  = Fraction.Shrink(measureLength + (((tempoEntry.LinearOffset - lastTempoOffset) / (entry.LinearOffset - lastTempoOffset)) * measureDistance));
                        tempoEntry.MetricMeasure = measure;
                        measureEntryList.Add(tempoEntry);
                    }

                    measureLength += measureDistance;

                    if (entry.Type == EntryType.Measure || entry.Type == EntryType.EndOfSong)
                    {
                        if (entry.LinearOffset != lastMeasureOffset)
                        {
                            // apply measure length to all entries in a tempo-changing measure
                            // so it's actually using the proper scale
                            foreach (Entry measureEntry in measureEntryList)
                            {
                                Fraction temp = measureEntry.MetricOffset;
                                temp /= measureLength;
                                measureEntry.MetricOffset = Fraction.Shrink(temp);
                                while ((double)measureEntry.MetricOffset >= 1)
                                {
                                    Fraction offs = measureEntry.MetricOffset;
                                    measureEntry.MetricMeasure++;
                                    offs.Numerator           -= offs.Denominator;
                                    measureEntry.MetricOffset = offs;
                                }
                            }
                            measureEntryList.Clear();
                            MeasureLengths[measure] = measureLength;
                            measure++;
                            lastMeasureOffset = Fraction.Shrink(entry.LinearOffset);
                            measureLength     = new Fraction(0, 1);
                        }
                        entry.MetricOffset  = new Fraction(0, 1);
                        entry.MetricMeasure = measure;
                    }
                    else if (entry.Type == EntryType.Tempo)
                    {
                        // on tempo change, update rate
                        bpm  = entry.Value;
                        rate = Util.CalculateMeasureRate(bpm);
                    }
                    lastTempoOffset = entry.LinearOffset;

                    // some measures have a defined length, use this on non-tempo-changing measures
                    // for best accuracy
                    if (lengthList.ContainsKey(measure))
                    {
                        tickMeasureLength = lengthList[measure];
                    }
                    else
                    {
                        tickMeasureLength = new Fraction(0, 1);
                    }

                    entryList.Clear();
                }

                // calculate metric offset
                if (tickMeasureLength.Numerator > 0)
                {
                    entry.MetricOffset  = Fraction.Shrink((entry.LinearOffset - lastTempoOffset) / tickMeasureLength);
                    entry.MetricMeasure = measure;
                    while ((double)entry.MetricOffset >= 1)
                    {
                        Fraction offs = entry.MetricOffset;
                        entry.MetricMeasure++;
                        offs.Numerator    -= offs.Denominator;
                        entry.MetricOffset = Fraction.Shrink(offs);
                    }
                }
                else
                {
                    entryList.Add(entry);
                }
            }
        }
 protected override bool ShouldRecieveRotationData(Fraction f, Cannon c) => !f.IsNeutral && f != Screen.LocalPlayerFraction;
Beispiel #48
0
 public CircleFr(PointFr p, Fraction r)
 {
     Center = p;
     Radius = r;
 }
Beispiel #49
0
        public void Reverse()
        {
            var x = new Fraction(2, 3);

            Assert.Equal(new Fraction(3, 2), x.Reverse());
        }
Beispiel #50
0
        public async Task <OperationResult> ImportFraction(FractionImportModel fractionsAsJson)
        {
            try
            {
                {
                    var rawJson        = JToken.Parse(fractionsAsJson.ImportList);
                    var rawHeadersJson = JToken.Parse(fractionsAsJson.Headers);

                    var headers         = rawHeadersJson;
                    var fractionObjects = rawJson.Skip(1);

                    foreach (var fractionObj in fractionObjects)
                    {
                        var numberExists       = int.TryParse(headers[0]?["headerValue"]?.ToString(), out var numberColumn);
                        var fractionNameExists = int.TryParse(headers[1]?["headerValue"]?.ToString(),
                                                              out var nameColumn);
                        if (numberExists || fractionNameExists)
                        {
                            var existingFraction = FindFraction(numberExists, numberColumn, fractionNameExists,
                                                                nameColumn, headers, fractionObj);
                            if (existingFraction == null)
                            {
                                var fractionModel =
                                    FractionsHelper.ComposeValues(new FractionModel(), headers, fractionObj);

                                var newFraction = new Fraction
                                {
                                    ItemNumber   = fractionModel.ItemNumber,
                                    Name         = fractionModel.Name,
                                    Description  = fractionModel.Description,
                                    LocationCode = fractionModel.LocationCode,
                                    eFormId      = fractionModel.eFormId
                                };
                                await newFraction.Create(_dbContext);
                            }
                            else
                            {
                                if (existingFraction.WorkflowState == Constants.WorkflowStates.Removed)
                                {
                                    var fraction = await _dbContext.Fractions.SingleOrDefaultAsync(x => x.Id == existingFraction.Id);

                                    if (fraction != null)
                                    {
                                        fraction.Name          = existingFraction.Name;
                                        fraction.Description   = existingFraction.Description;
                                        fraction.ItemNumber    = existingFraction.ItemNumber;
                                        fraction.LocationCode  = existingFraction.LocationCode;
                                        fraction.WorkflowState = Constants.WorkflowStates.Created;

                                        await fraction.Update(_dbContext);
                                    }
                                }
                            }
                        }
                    }
                }
                return(new OperationResult(true,
                                           _trashInspectionLocalizationService.GetString("FractionCreated")));
            }
            catch (Exception e)
            {
                Trace.TraceError(e.Message);
                _coreHelper.LogException(e.Message);
                return(new OperationResult(false,
                                           _trashInspectionLocalizationService.GetString("ErrorWhileCreatingFraction")));
            }
        }
Beispiel #51
0
        public void ReductionOnCreation()
        {
            var x = new Fraction(3, 6);

            Assert.Equal(new Fraction(1, 2), x);
        }
Beispiel #52
0
        //### Methods

        public void PrintTimeSignature()
        {
            Console.WriteLine("> " + Fraction.ToString() + " - Valid at " + ValidAt.ToString());
        }
 public Fraction Subtract(Fraction fraction1, Fraction fraction2)
 {
     return(new Fraction(((fraction1.Numerator * fraction2.Denominator) - (fraction2.Numerator * fraction1.Denominator)),
                         (fraction1.Denominator * fraction2.Denominator)));
 }
Beispiel #54
0
 /// <summary>
 /// Compares two fractions
 /// </summary>
 /// <param name="expected"></param>
 /// <param name="actual"></param>
 /// <returns></returns>
 public static bool CompareFraction(Fraction expected, Fraction actual)
 {
     return expected == actual;
 }
Beispiel #55
0
        private static void InitializeSchedules()
        {
            WasteManagement wasteMgmt01 = new WasteManagement {
                Name = "AffaldPlus"
            };

            if (!context.WasteManagements.Any())
            {
                context.WasteManagements.Add(wasteMgmt01);
            }

            User user01 = new User {
                FirstName = "Chris", LastName = "Sakellarios"
            };
            User user02 = new User {
                FirstName = "Charlene", LastName = "Campbell"
            };
            User user03 = new User {
                FirstName = "Mattie", LastName = "Lyons"
            };
            User user04 = new User {
                FirstName = "Kelly", LastName = "Alvarez"
            };
            User user05 = new User {
                FirstName = "Charlie", LastName = "Cox"
            };
            User user06 = new User {
                FirstName = "Megan", LastName = "Fox"
            };

            if (!context.Users.Any())
            {
                context.Users.Add(user01); context.Users.Add(user02);
                context.Users.Add(user03); context.Users.Add(user04);
                context.Users.Add(user05); context.Users.Add(user06);
            }

            Hub hub01 = new Hub {
                Name = "Canadien Hubs", Location = "G4", WasteManagementId = wasteMgmt01.Id
            };
            Hub hub02 = new Hub {
                Name = "Hubsa", Location = "J4", WasteManagementId = wasteMgmt01.Id
            };
            Hub hub03 = new Hub {
                Name = "Downtown", Location = "C3", WasteManagementId = wasteMgmt01.Id
            };
            Hub hub04 = new Hub {
                Name = "Seje Hub", Location = "D2", WasteManagementId = wasteMgmt01.Id
            };
            Hub hub05 = new Hub {
                Name = "Wazzup Hub", Location = "A1", WasteManagementId = wasteMgmt01.Id
            };

            if (!context.Hubs.Any())
            {
                context.Hubs.Add(hub01); context.Hubs.Add(hub02);
                context.Hubs.Add(hub03); context.Hubs.Add(hub04);
                context.Hubs.Add(hub05);
            }

            Fraction fraction01 = new Fraction {
                HubId = hub01.Id, UserId = user01.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction02 = new Fraction {
                HubId = hub02.Id, UserId = user02.Id, IsClean = true, Weight = 0.5
            };
            Fraction fraction03 = new Fraction {
                HubId = hub03.Id, UserId = user03.Id, IsClean = true, Weight = 1.6
            };
            Fraction fraction04 = new Fraction {
                HubId = hub04.Id, UserId = user01.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction05 = new Fraction {
                HubId = hub05.Id, UserId = user04.Id, IsClean = false, Weight = 0.73
            };
            Fraction fraction06 = new Fraction {
                HubId = hub01.Id, UserId = user05.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction07 = new Fraction {
                HubId = hub01.Id, UserId = user05.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction08 = new Fraction {
                HubId = hub01.Id, UserId = user01.Id, IsClean = false, Weight = 0.73
            };
            Fraction fraction09 = new Fraction {
                HubId = hub02.Id, UserId = user02.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction10 = new Fraction {
                HubId = hub03.Id, UserId = user03.Id, IsClean = true, Weight = 0.73
            };
            Fraction fraction11 = new Fraction {
                HubId = hub04.Id, UserId = user01.Id, IsClean = true, Weight = 0.73
            };

            if (!context.Fractions.Any())
            {
                context.Fractions.Add(fraction01); context.Fractions.Add(fraction02);
                context.Fractions.Add(fraction03); context.Fractions.Add(fraction04);
                context.Fractions.Add(fraction05); context.Fractions.Add(fraction06);
                context.Fractions.Add(fraction07); context.Fractions.Add(fraction08);
                context.Fractions.Add(fraction09); context.Fractions.Add(fraction10);
                context.Fractions.Add(fraction11);
            }

            UserHub userHub01 = new UserHub {
                HubId = hub01.Id, UserId = user01.Id
            };
            UserHub userHub02 = new UserHub {
                HubId = hub02.Id, UserId = user02.Id
            };
            UserHub userHub03 = new UserHub {
                HubId = hub03.Id, UserId = user03.Id
            };
            UserHub userHub04 = new UserHub {
                HubId = hub04.Id, UserId = user01.Id
            };
            UserHub userHub05 = new UserHub {
                HubId = hub05.Id, UserId = user04.Id
            };
            UserHub userHub06 = new UserHub {
                HubId = hub01.Id, UserId = user05.Id
            };

            if (!context.UserHubs.Any())
            {
                context.Add(userHub01); context.Add(userHub02);
                context.Add(userHub03); context.Add(userHub04);
                context.Add(userHub05); context.Add(userHub06);
            }

            context.SaveChanges();
        }
Beispiel #56
0
        /// <summary>
        /// Static initialization.
        /// </summary>
        static SMCommon()
        {
            // Initialize valid SM SubDivisions.
            SubDivisions.Add(new Fraction(0, 0));
            foreach (var denominator in ValidDenominators)
            {
                if (denominator <= 1)
                {
                    continue;
                }
                for (var numerator = 0; numerator < denominator; numerator++)
                {
                    var fraction = new Fraction(numerator, denominator);
                    if (!SubDivisions.Contains(fraction))
                    {
                        SubDivisions.Add(fraction);
                    }
                }
            }

            SubDivisions.Sort();
            foreach (var subDivision in SubDivisions)
            {
                SubDivisionLengths.Add(subDivision.ToDouble());
            }

            // Initialize ChartProperties.
            Properties = new ChartProperties[Enum.GetNames(typeof(ChartType)).Length];
            Properties[(int)ChartType.dance_single] = new ChartProperties {
                NumInputs = 4, NumPlayers = 1
            };
            Properties[(int)ChartType.dance_double] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.dance_couple] = new ChartProperties {
                NumInputs = 8, NumPlayers = 2
            };
            Properties[(int)ChartType.dance_solo] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.dance_threepanel] = new ChartProperties {
                NumInputs = 3, NumPlayers = 1
            };
            Properties[(int)ChartType.dance_routine] = new ChartProperties {
                NumInputs = 8, NumPlayers = 2
            };
            Properties[(int)ChartType.pump_single] = new ChartProperties {
                NumInputs = 5, NumPlayers = 1
            };
            Properties[(int)ChartType.pump_halfdouble] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.pump_double] = new ChartProperties {
                NumInputs = 10, NumPlayers = 1
            };
            Properties[(int)ChartType.pump_couple] = new ChartProperties {
                NumInputs = 10, NumPlayers = 2
            };
            Properties[(int)ChartType.pump_routine] = new ChartProperties {
                NumInputs = 10, NumPlayers = 2
            };
            Properties[(int)ChartType.kb7_single] = new ChartProperties {
                NumInputs = 7, NumPlayers = 1
            };
            Properties[(int)ChartType.ez2_single] = new ChartProperties {
                NumInputs = 5, NumPlayers = 1
            };
            Properties[(int)ChartType.ez2_double] = new ChartProperties {
                NumInputs = 10, NumPlayers = 1
            };
            Properties[(int)ChartType.ez2_real] = new ChartProperties {
                NumInputs = 7, NumPlayers = 1
            };
            Properties[(int)ChartType.para_single] = new ChartProperties {
                NumInputs = 5, NumPlayers = 1
            };
            Properties[(int)ChartType.ds3ddx_single] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_single5] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_versus5] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_double5] = new ChartProperties {
                NumInputs = 12, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_single7] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_versus7] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.bm_double7] = new ChartProperties {
                NumInputs = 16, NumPlayers = 1
            };
            Properties[(int)ChartType.maniax_single] = new ChartProperties {
                NumInputs = 4, NumPlayers = 1
            };
            Properties[(int)ChartType.maniax_double] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_single4] = new ChartProperties {
                NumInputs = 4, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_single5] = new ChartProperties {
                NumInputs = 5, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_single8] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_double4] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_double5] = new ChartProperties {
                NumInputs = 10, NumPlayers = 1
            };
            Properties[(int)ChartType.techno_double8] = new ChartProperties {
                NumInputs = 16, NumPlayers = 1
            };
            Properties[(int)ChartType.pnm_five] = new ChartProperties {
                NumInputs = 5, NumPlayers = 1
            };
            Properties[(int)ChartType.pnm_nine] = new ChartProperties {
                NumInputs = 9, NumPlayers = 1
            };
            Properties[(int)ChartType.lights_cabinet] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.kickbox_human] = new ChartProperties {
                NumInputs = 4, NumPlayers = 1
            };
            Properties[(int)ChartType.kickbox_quadarm] = new ChartProperties {
                NumInputs = 4, NumPlayers = 1
            };
            Properties[(int)ChartType.kickbox_insect] = new ChartProperties {
                NumInputs = 6, NumPlayers = 1
            };
            Properties[(int)ChartType.kickbox_arachnid] = new ChartProperties {
                NumInputs = 8, NumPlayers = 1
            };
        }
        private bool TryParseFractionTimespan(IEnumerable <Token> tokens, out TimeSpan ts)
        {
            ts = new TimeSpan();
            bool expectingUnit = false;

            var    enumerator = tokens.GetEnumerator();
            double amount     = 0.0;

            while (enumerator.MoveNext())
            {
                Token token = enumerator.Current;
                if (token.Type == TokenType.WhiteSpace)
                {
                    continue;
                }
                if (token.Type == TokenType.Character && expectingUnit)
                {
                    char first = token.Value [0];
                    expectingUnit = false;
                    switch (first)
                    {
                    case 'd':
                    case 'D':
                        ts += TimeSpan.FromDays(amount);
                        break;

                    case 'h':
                    case 'H':
                        ts += TimeSpan.FromHours(amount);
                        break;

                    case 'm':
                    case 'M':
                        ts += TimeSpan.FromMinutes(amount);
                        break;

                    case 's':
                    case 'S':
                        ts += TimeSpan.FromSeconds(amount);
                        break;

                    default:
                        return(false);
                    }
                }
                else if (token.Type == TokenType.Number || token.Type == TokenType.Sentinal)
                {
                    if (expectingUnit)
                    {
                        // We already have a number, so use the Default unit and add it first,
                        // before we process this current token.

                        switch (DefaultUnit)
                        {
                        case TimeUnit.Days:
                            ts += TimeSpan.FromDays(amount);
                            break;

                        case TimeUnit.Hours:
                            ts += TimeSpan.FromHours(amount);
                            break;

                        case TimeUnit.Minutes:
                            ts += TimeSpan.FromMinutes(amount);
                            break;

                        case TimeUnit.Seconds:
                            ts += TimeSpan.FromSeconds(amount);
                            break;

                        default:
                            return(false);
                        }
                    }
                    if (token.Type == TokenType.Sentinal)
                    {
                        return(true);
                    }
                    Fraction famount;
                    if (Fraction.TryParse(token.Value, out famount))
                    {
                        amount = famount.ToDouble();
                    }
                    else if (!double.TryParse(token.Value, out amount))
                    {
                        return(false);
                    }
                    expectingUnit = true;
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #58
0
 public TimeSignature(Fraction fraction, Fraction validAt)
 {
     Fraction = new Fraction(fraction.Numerator, fraction.Denominator);
     ValidAt  = new Fraction(validAt.Numerator, validAt.Denominator);
 }
        private void Button_Warmstart(object sender, RoutedEventArgs e)
        {
            string temp = Microsoft.VisualBasic.Interaction.InputBox("Enter Warmstart restriction", "Warmstart", "");

            if (temp == "")
            {
                return;
            }

            string[] splitW = temp.Split(' ');

            DeepCopyTableau();

            tableau = new Fraction[oldtableau.Length + 1][];

            for (int i = 0; i < tableau.Length - 1; i++)
            {
                tableau[i] = new Fraction[oldtableau[0].Length];
                for (int j = 0; j < oldtableau[0].Length; j++)
                {
                    tableau[i][j] = new Fraction(oldtableau[i][j].Numerator, oldtableau[i][j].Denominator);
                }
            }

            tableau[tableau.Length - 1] = new Fraction[oldtableau[0].Length];

            for (int j = 0; j < splitW.Length; j++)
            {
                if (splitW[j].Contains("x"))
                {
                    int    xi = splitW[j].IndexOf('x');
                    string xl = splitW[j].Remove(xi);
                    if (xl.Contains("+"))
                    {
                        xl = xl.Replace("+", "");
                    }
                    if (xl.Trim().Equals(""))
                    {
                        xl = "1";
                    }
                    if (xl.Trim().Equals("-"))
                    {
                        xl = "-1";
                    }
                    tableau[tableau.Length - 1][j] = Fraction.FromString(xl);
                }
                else if (splitW[j].Contains("="))
                {
                    string xl = splitW[j].Replace("=", "");
                    tableau[tableau.Length - 1][j] = Fraction.FromString(xl);
                }
                else
                {
                    tableau[tableau.Length - 1][j] = Fraction.FromString(splitW[j]);
                }
            }

            string[] newXL = new string[labelX.Length + 1];
            string[] newYL = new string[labelY.Length + 1];

            for (int i = 0; i < labelX.Length; i++)
            {
                newXL[i] = labelX[i];
                newYL[i] = labelY[i];
            }

            newXL[labelX.Length] = "s1";
            newYL[labelY.Length] = "t1";

            labelX = newXL;
            labelY = newYL;

            DrawTableau();
        }
        private void Button_Setup(object sender, RoutedEventArgs e)
        {
            string[] maxfct = function.Text.Split(' ');

            string[] restrictions = st.Text.Split('\n');

            //add ci and z(x)
            tableau    = new Fraction[restrictions.Length + 1][];
            tableau[0] = new Fraction[maxfct.Length + 1];
            int l = 0;

            foreach (string cs in maxfct)
            {
                if (cs.Contains("x"))
                {
                    int    xi = cs.IndexOf('x');
                    string to = cs.Remove(xi);
                    if (to.Contains("+"))
                    {
                        to = to.Replace("+", "");
                    }
                    if (to.Trim().Equals(""))
                    {
                        to = "1";
                    }
                    if (to.Trim().Equals("-"))
                    {
                        to = "-1";
                    }
                    tableau[0][l] = Fraction.FromString(to) * -1;
                }
                else
                {
                    tableau[0][l] = Fraction.FromString(cs) * -1;
                }
                l++;
            }
            tableau[0][maxfct.Length] = new Fraction(0);

            for (int i = 0; i < restrictions.Length; i++)
            {
                string[] restSpl = restrictions[i].Split(' ');
                tableau[i + 1] = new Fraction[restSpl.Length];

                for (int j = 0; j < restSpl.Length; j++)
                {
                    if (restSpl[j].Contains("x"))
                    {
                        int    xi = restSpl[j].IndexOf('x');
                        string xl = restSpl[j].Remove(xi);
                        if (xl.Contains("+"))
                        {
                            xl = xl.Replace("+", "");
                        }
                        if (xl.Trim().Equals(""))
                        {
                            xl = "1";
                        }
                        if (xl.Trim().Equals("-"))
                        {
                            xl = "-1";
                        }
                        tableau[i + 1][j] = Fraction.FromString(xl);
                    }
                    else if (restSpl[j].Contains("="))
                    {
                        string xl = restSpl[j].Replace("=", "");
                        tableau[i + 1][j] = Fraction.FromString(xl);
                    }
                    else
                    {
                        tableau[i + 1][j] = Fraction.FromString(restSpl[j]);
                    }
                }
            }

            //Fill Label Arrays
            labelX = new string[(tableau.Length + tableau[0].Length - 2)];
            labelY = new string[(tableau.Length + tableau[0].Length - 2)];
            for (int i = 0; i < (tableau.Length + tableau[0].Length - 2); i++)
            {
                labelX[i] = "x" + (i + 1);
                labelY[i] = "y" + (i + 1);
            }

            DrawTableau();
        }