Code Monkey home page Code Monkey logo

towerbreakers's Introduction

towerBreakers

Two players are playing a game of Tower Breakers! Player always moves first, and both players always play optimally. Two players are playing a game of Tower Breakers! Player always moves first, and both players always play optimally.The rules of the game are as follows:

Initially there are towers. Each tower is of height . The players move in alternating turns. In each turn, a player can choose a tower of height and reduce its height to , where and evenly divides . If the current player is unable to make a move, they lose the game. Given the values of and , determine which player will win. If the first player wins, return . Otherwise, return .

Example.

There are towers, each units tall. Player has a choice of two moves:

  • remove pieces from a tower to leave as
  • remove pieces to leave

Let Player remove . Now the towers are and units tall.

Player matches the move. Now the towers are both units tall.

Now Player has only one move.

Player removes pieces leaving . Towers are and units tall. Player matches again. Towers are both unit tall.

Player has no move and loses. Return .

Function Description

Complete the towerBreakers function in the editor below.

towerBreakers has the following paramter(s):

int n: the number of towers int m: the height of each tower Returns

int: the winner of the game Input Format

The first line contains a single integer , the number of test cases. Each of the next lines describes a test case in the form of space-separated integers, and .

Constraints

Sample Input

STDIN Function


2 t = 2 2 2 n = 2, m = 2 1 4 n = 1, m = 4 Sample Output

2 1 Explanation

We'll refer to player as and player as

In the first test case, chooses one of the two towers and reduces it to . Then reduces the remaining tower to a height of . As both towers now have height , cannot make a move so is the winner.

In the second test case, there is only one tower of height . can reduce it to a height of either or . chooses as both players always choose optimally. Because has no possible move, wins. image

image

towerbreakers's People

Contributors

peterturkson102 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.