Cerinta completa

Poker Nim is another -player game that’s a simple variation on a Nim game. The rules of the games are as follows:

  • The game starts with piles of chips indexed from to . Each pile (where ) has chips.
  • The players move in alternating turns. During each move, the current player must perform either of the following actions:

    • Remove one or more chips from a single pile.
    • Add one or more chips to a single pile.

    At least chip must be added or removed during each turn.

  • To ensure that the game ends in finite time, a player cannot add chips to any pile more than times.
  • The player who removes the last chip wins the game.

Given the values of , , and the numbers of chips in each of the piles, determine whether the person who wins the game is the first or second person to move. Assume both players move optimally.

Input Format

The first line contains an integer, , denoting the number of test cases.
Each of the subsequent lines defines a test case. Each test case is described over the following two lines:

  1. Two space-separated integers, (the number of piles) and (the maximum number of times an individual player can add chips to some pile ), respectively.
  2. space-separated integers, , where each describes the number of chips at pile .

Constraints

Output Format

For each test case, print the name of the winner on a new line (i.e., either or ).

Sample Input

2
2 5
1 2
3 5
2 1 3

Sample Output

First
Second

Limbajul de programare folosit: python3

Cod:

#!/bin/python3

import math
import os
import random
import re
import sys
from functools import reduce

# Complete the pokerNim function below.
def pokerNim(k, c):
    res = reduce((lambda x, y: x ^ y), c)

    if res == 0:
        return 'Second'
    else:
        return 'First'

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    t = int(input())

    for t_itr in range(t):
        nk = input().split()

        n = int(nk[0])

        k = int(nk[1])

        c = list(map(int, input().rstrip().split()))

        result = pokerNim(k, c)

        fptr.write(result + '\n')

    fptr.close()

Scor obtinut: 1.0

Submission ID: 464605415

Link challenge: https://www.hackerrank.com/challenges/poker-nim-1/problem

Poker Nim