コード例 #1
0
ファイル: Day_21.cs プロジェクト: LEPT0N/toybox
            public void take_turn(c_dice dice)
            {
                position += dice.roll();
                position += dice.roll();
                position += dice.roll();

                while (position > k_max_board_position)
                {
                    position -= k_max_board_position;
                }

                score += position;
            }
コード例 #2
0
ファイル: Day_21.cs プロジェクト: LEPT0N/toybox
        public static void Part_1(
            string input,
            bool pretty)
        {
            c_player[] players = parse_input(input, pretty);

            c_dice dice           = new c_dice();
            int    current_player = 0;

            while (players.All(player => player.score < k_winning_score))
            {
                players[current_player].take_turn(dice);

                current_player = (current_player + 1) % 2;
            }

            UInt64 losing_score = players.Min(player => player.score);
            UInt64 result       = losing_score * dice.roll_count;

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine();
            Console.WriteLine("Result = {0}", result);
            Console.ResetColor();
        }