Puzzle | Game of Brussels Sprouts

Given n number of spots, and two players. Players need to connect any two spots without intersecting any of the drawn line, the player who cannot give a move, loses. Determine who will win player1 or player2. Examples :

Input : n = 2
Output : player 2

Input : n = 3
Output : player 1

Explanation :  

Method : The winner of this game does not depend on the moves the players choose, rather it only depends on n. This problem can be solved using Euler Characteristics. According to Euler Characteristics : For every surface S there exists an integer such that whenever a graph G with V vertices and E edges is embedded in S so that there are F faces(regions divided by the graph), then : 

   

Solution Approach using Euler Characteristics:
Observations :

C++

// C++ code to find out winner
// of Brussels Sprouts game.
#include <iostream>
using namespace std;
 
// Function to find out winner of
// the game.
void winner(int n)
{
 
    // Total number of moves m.
    int m = 5 * n - 2;
 
    // If m is odd Player 1 is winner
    // If m is even Player 2 is winner.
    if (m % 2 == 1)
        cout << "Player 1" << endl;
    else
        cout << "Player 2" << endl;
}
 
// Driver code
int main()
{
    // Test case 1
    int n1 = 2;
    winner(n1);
 
    // Test case 2
    int n2 = 3;
    winner(n2);
 
    return 0;
}

                    

Java

// Java code to find out winner
// of Brussels Sprouts game.
 
import java.io.*;
 
class GFG {
     
    // Function to find out winner of
    // the game.
    static void winner(int n)
    {
 
        // Total number of moves m.
        int m = 5 * n - 2;
 
        // If m is odd Player 1 is winner
        // If m is even Player 2 is winner.
        if (m % 2 == 1)
            System.out.println("Player 1");
        else
            System.out.println("Player 2");
    }
 
    // Driver code
    public static void main(String[] args)
    {
 
        // Test case 1
        int n1 = 2;
        winner(n1);
 
        // Test case 2
        int n2 = 3;
        winner(n2);
    }
}
 
// This code is contributed by vt_m.

                    

Python3

# Python code to find out winner
# of Brussels Sprouts game.
 
# Function to find out winner of
# the game.
def winner(n):
 
    # Total number of moves m.
    m = 5 * n - 2
 
    # If m is odd Player 1 is winner
    # If m is even Player 2 is winner.
    if m % 2 == 1:
        print("Player 1")
    else:
        print("Player 2")
 
 # Driver code
 
 # Test case 1
n1 = 2
winner(n1)
 
 # Test case 2
n2 = 3
winner(n2)
 
# The code is contributed by Nidhi goel.

                    

C#

// C# code to find out winner
// of Brussels Sprouts game.
using System;
 
class GFG {
 
  // Function to find out winner of
  // the game.
  public static void winner(int n)
  {
 
    // Total number of moves m.
    int m = 5 * n - 2;
 
    // If m is odd Player 1 is winner
    // If m is even Player 2 is winner.
    if (m % 2 == 1)
      Console.WriteLine("Player 1");
    else
      Console.WriteLine("Player 2");
  }
 
  static void Main() {
 
    // Test case 1
    int n1 = 2;
    winner(n1);
 
    // Test case 2
    int n2 = 3;
    winner(n2);
  }
}
 
// The code is contributed by Nidhi goel.

                    

Javascript

// javascript code to find out winner
// of Brussels Sprouts game.
 
// Function to find out winner of
// the game.
function winner(n)
{
 
    // Total number of moves m.
    let m = 5 * n - 2;
 
    // If m is odd Player 1 is winner
    // If m is even Player 2 is winner.
    if (m % 2 == 1)
        console.log("Player 1");
    else
        console.log("Player 2");
}
 
// Driver code
// Test case 1
let n1 = 2;
winner(n1);
 
// Test case 2
let n2 = 3;
winner(n2);
 
// The code is contributed by Nidhi goel.

                    
Output:
Player 2
Player 1