Ejemplo n.º 1
0
        public static void Main(string[] argv)
        {
            // You have a `DiceSet` class which has a list for 6 dice
            // You can roll all of them with roll()
            // Check the current rolled numbers with getCurrent()
            // You can reroll with reroll()
            // Your task is to roll the dice until all of the dice are 6

            DiceSet diceSet = new DiceSet();

            diceSet.Roll();

            for (int i = 0; i < 6; i++)
            {
                while (diceSet.GetCurrent(i) != 6)
                {
                    diceSet.Reroll(i);
                }
            }

            for (int i = 0; i < 6; i++)
            {
                Console.WriteLine(diceSet.GetCurrent(i));
            }
        }
        public static void Main(string[] argv)
        {
            // You have a `DiceSet` class which has a list for 6 dice
            // You can roll all of them with roll()
            // Check the current rolled numbers with getCurrent()
            // You can reroll with reroll()
            // Your task is to roll the dice until all of the dice are 6
            DiceSet diceSet = new DiceSet();

            diceSet.Roll();
            // version 1
            bool allSix  = false;
            bool isSix   = false;
            int  counter = 0;

            while (!allSix)
            {
                for (int i = 0; i < diceSet.GetCurrent().Length; i++)
                {
                    if (diceSet.GetCurrent(i) != 6)
                    {
                        isSix = false;
                        break;
                    }
                    else
                    {
                        isSix = true;
                    }
                }
                if (isSix)
                {
                    allSix = true;
                    break;
                }
                counter++;
                Array.ForEach(diceSet.GetCurrent(), Console.Write);
                diceSet.Reroll();
            }
            if (isSix)
            {
                Console.WriteLine();
                Console.WriteLine($"We needed {counter} trials");
                Console.WriteLine("All die are six");
                Array.ForEach(diceSet.GetCurrent(), Console.Write);
            }

            /*// version 2
             * int counter2 = 0;
             * for (int dice = 0; dice < diceSet.GetCurrent().Length; dice++)
             * {
             *  while (diceSet.GetCurrent(dice) != 6)
             *  {
             *      diceSet.Reroll(dice);
             *      counter2++;
             *  }
             * }
             * Array.ForEach(diceSet.GetCurrent(), Console.WriteLine);
             * Console.WriteLine(counter2);*/
        }
Ejemplo n.º 3
0
        public static void Main(string[] argv)
        {
            // You have a `DiceSet` class which has a list for 6 dice
            // You can roll all of them with roll()
            // Check the current rolled numbers with getCurrent()
            // You can reroll with reroll()
            // Your task is to roll the dice until all of the dice are 6
            DiceSet diceSet = new DiceSet();

            /*diceSet.GetCurrent();
             * diceSet.Roll();
             * Console.WriteLine("\n");
             * diceSet.GetCurrent();
             * Console.WriteLine("\n");
             * Console.WriteLine(diceSet.GetCurrent(5)); ;
             * Console.WriteLine("\n");*/

            diceSet.Reroll();
            diceSet.GetCurrent();

            /*Console.WriteLine("\n");
             *
             *
             * diceSet.Reroll(0);
             * diceSet.GetCurrent();
             * Console.WriteLine("\n");
             * diceSet.Reroll(1);
             * diceSet.GetCurrent();
             * Console.WriteLine("\n");
             * diceSet.Reroll(2);
             * diceSet.GetCurrent();
             * Console.WriteLine("\n");
             * diceSet.Reroll(3);
             * diceSet.GetCurrent();*/
        }