Programming Articles - Page 937 of 3366

Program to reset a polygon to its initial state in Python

Arnab Chakraborty
Updated on 23-Oct-2021 08:05:20

217 Views

Suppose, there is a polygon with n vertices, n flipping axis, and n rotation points. The following are true for the flipping axes and rotation pointsIf n is odd, each flipping axis passes through only one vertex and the middle of the opposite side.If n is even, half of the axes pass through a pair of opposite vertex and the other half passes through a pair of opposite sides.Two following axes have an angle of 360/2n.Now, we rotate the polygon provided. We have n different types of rotators, a k-rotator rotates the polygon at axis k clockwise by (360 x ... Read More

Program to find out the cells containing maximum value in a matrix in Python

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

288 Views

Suppose, there is a n x n matrix initialized with 0s. Now, a list is given and it contains some pairs that contain a particular row and a column position. For each item i in the list, the contents of the cells increase by 1 where the row number and the column number are less than the row value and column value of item i in the list. After all the list elements have been traversed, we have to find out the number of cells in the matrix that contains the maximum value. (row and column index start at 0)So, ... Read More

Program to find out number of blocks that can be covered in Python

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

329 Views

Suppose there are n blocks in a path, and a worker is putting colored tiles on the blocks. The worker is putting blocks in a way, such that if a block number in the path is divisible by 4 or/and 2 but not 42, he puts a colored tile there. We have to find out the number of blocks he can cover if he has started with k number of colored tiles.So, if the input is like k = 16, then the output will be 32.To solve this, we will follow these steps −MOD = 10^9 + 7quotient := floor ... Read More

Program to apply Russian Peasant Multiplication in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:52:50

527 Views

Suppose we are given four integer numbers p, q, r, and k. We will use a method called the Russian Peasant Multiplication method and determine the value of (p + q.i)^r = r + s.i. We have to return the value of r mod k and s mod k.So, if the input is like p = 3, q = 0, r = 8, k = 10000, then the output will be (6561, 0) 3^8 = 6561, as q = 0 value of r mod k = 6561.To solve this, we will follow these steps −if r is same as 0, ... Read More

Program to find out the number of integral coordinates on a straight line between two points in Python

Arnab Chakraborty
Updated on 23-Oct-2021 07:50:14

306 Views

Suppose, we have been provided with two points (p1, q1) and (p2, q2). We have to find out the number of integral coordinates (both the x and y values are integers) if a straight line is drawn between the two given points. The number of points is returned.So, if the input is like p1 = 3, q1 = 3, p2 = 6, q2 = 6, then the output will be 2 If we draw the straight line, we will see that the points (5, 5) and (6, 6) are situated on the straight line.To solve this, we will follow these ... Read More

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

312 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

394 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

214 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

231 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

130 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

Advertisements