Python Articles - Page 338 of 1048

Program to find number of possible moves to start the game to win by the starter in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:47:51

334 Views

Suppose Amal and Bimal are playing a game. They have n containers with one or more chocolates inside it. These containers are numbered from 1 to N, where ith container has count[i] number of chocolates. Now the game is like. First player will select a container and take one or more chocolates from it. Then the second player will select a non-empty container and take one or more chocolates from it, like this they play alternatively. When one of the players has no way to take any chocolates, then he/she loses the game. If Amal's turn is first we have ... Read More

Program to find winner of a rower breaking game in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:44:55

426 Views

Suppose we have an array height. There are n different towers with different height. Amal and Bimal are playing a game. The game rules are like belowAmal always plays firstDuring each move, the current player selects a tower of height X and break it down into Y different towers of height Z each. [Y*Z = X; X and Y > 1]Whoever has no move will lose the gameWe have to find the winner's name.So, if the input is like height = [3, 1, 2], then the output will be Bimal, because the initial heights are {3, 1, 2}. If Amal ... Read More

Program to find winner of a set element removal game in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:33:09

251 Views

Suppose We have a set of first n natural numbers {1..n}. Amal and Bimal are playing a game.The game rules are like belowAmal always plays firstDuring each move, the current player selects a prime number p from the set. The player then removes p and all of its multiples from the set.Whoever has no move will lose the game If we have n, we have to find the winner name.So, if the input is like n = 5, then the output will be Amal, because the initial set is {1, 2, 3, 4, 5}. Now let Amal selects a number ... Read More

Program to find winner of number reducing game in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:30:31

248 Views

Suppose Amal and Bimal are playing a game. They have a number n and they check whether it is a power of 2 or not. If it is, they divide it by 2. otherwise, they reduce it by the next lower number which is also a power of 2. Whoever reduces the number to 1 will win the game. Amal always starts the game, then we have to find the winner's name.So, if the input is like n = 19, then the output will be Amal because, 19 is not power of 2, so Amal reduces it to 16, then ... Read More

Program to find number of magic sets from a permutation of first n natural numbers in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:27:51

149 Views

Suppose we have an array A with first n natural numbers, and one permutation P{p1, p2, ... pn} of array A. We have to check how many magic sets are there. A permutation is said to be magic set, if this satisfies these few rules −If we have k, then the elements in positions a[1], a[2], ... a[k] are less than their adjacent elements [P[a[i] - 1] > P[a[i]] < P[a[i] + 1]]If we have l, then the elements in positions b[1], b[2], ... b[l] are greater than their adjacent elements [P[b[i] - 1] < P[b[i]] > P[b[i] + 1]]So, ... Read More

Program to find number of sequences after adjacent k swaps and at most k swaps in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:23:12

413 Views

Suppose we have an array A with first n natural numbers. We have to find how many sequences (S1) can we get after exact k adjacent swaps on A? And how many sequences (S2) can we get after at most k swaps on A? Here the adjacent swap means swapping elements at index i and i+1.So, if the input is like n = 3 k = 2, then the output will be 3, 6 because −Original array was [1, 2, 3]After 2 adjacent swaps: we can get [1, 2, 3], [2, 3, 1], [3, 1, 2] So S1 = 3After ... Read More

Program to find number of strictly increasing colorful candle sequences are there in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:19:41

268 Views

Suppose there are n candles which are aligned from left to right. The i-th candle from the left side has the height h[i] and the color c[i]. We also have an integer k, represents there are colors in range 1 to k. We have to find how many strictly increasing colorful sequences of candies are there? The increasing sequence is checked based on heights, and a sequence is said to be colorful if there are at least one candle of each color in range 1 to K are available. If the answer is too large, then return result mod 10^9 ... Read More

Program to find number of starting point from where we can start travelling in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:13:46

514 Views

Suppose there are n cities numbered from 0 to n-1 and there are n directed roads. We can travel from city i to city (i + 1) % n [0 to 1 to 2 to .... to N - 1 to 0]. We have a car. The capacity of our car's fuel tank is cap unitss. There are fuel[i] units of fuel we can use at the beginning of city i and the car takes cost[i] units of fuel to travel from city i to (i + 1) % n. We have to find how many cities are there from ... Read More

Program to check robbers can rob the vault or not in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:11:05

151 Views

Suppose there are N number of robbers are trying to rob a vault. There was a guard but he went out for G amount of time, after that he will come back. And each robber has specific time to rob the vault, but at most two of them can enter into the vault at the same time. Now the problem is we have to check whether they can rob the vault of getting caught by the guard? We have to keep in mind that −If one robber goes inside the vault at a time t and at the same time ... Read More

Program to find maximum score of brick removal game in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:03:30

277 Views

Suppose Amal and Bimal are playing a game. They have an array nums which determines n bricks with numbered on top of it. In this game, players can alternatively remove one, two or three bricks from the top, and the numbers marked on the removed bricks are added to the score of that player. If always Amal starts first, we have to find how much score Amal get secure at maximum.So, if the input is like nums = [1, 2, 3, 4, 5], then the output will be 6 because, Amal can remove brick {1}, {1, 2} or {1, 2, ... Read More

Advertisements