Programming Articles - Page 934 of 3366

Program to find value of find(x, y) is even or odd in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:43:58

274 Views

Suppose we have an array nums. We also have another pair (x, y), we need to find whether the value find(x, y) is Odd or Even. The find() is as followsfind(x, y) = 1 if x > yfind(x, y) = nums[x]^find(x+1, y) otherwiseSo, if the input is like nums = [3, 2, 7] (x, y) = 1, 2, then the output will be even, because −find(1, 2) = nums[1]^find(2, 3)find(2, 2) = nums[2]^find(3, 2)find(3, 2) = 1, so find(2, 2) = 7, and find(1, 2) = 2^7 = 128, this is evenTo solve this, we will follow these steps −even ... Read More

Program find number of subsets of colorful vertices that meets given conditions in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:41:12

154 Views

Suppose we have an array colors, representing colors for one regular n-gon. Here each vertex of this n-gon was randomly colored with one of n different colors present in the given array. We have to find the number of special subsets of polygon vertices, such that these subsets meet these conditions −The size of subset must be at least two.If we remove vertices which are present in the subset, from the polygon (the adjacent edges of those vertices will also get removed), then the remaining vertices and edges form some continuous paths.None of those paths should contain two vertices of ... Read More

Program to find number of expected moves required to win Lotus and Caterpillar game in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:36:43

184 Views

Suppose we have a grid with n rows and m columns. Amal and Bimal are playing a game on that grid. The game rule is like below −Amal places white lotus tile somewhere at the top row and Bimal places a caterpillar tile somewhere on the bottom row. Amal starts the game and they are playing alternatively. Amal can move his tile to any of the 8 adjacent cells inside the grid of the current cell, but Bimal's caterpillar tile can only move left or right inside the grid, or stay at the same position. Amal's goal is to catch ... Read More

Program to find expected growth of virus after time t in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:30:32

215 Views

Suppose there is a dangerous virus and that grows rapidly. The probability of number of virus cells growing by a factor x is 0.5 and also the probability of number of virus cells growing by a factor y is 0.5. Now if there was a single cell of virus at beginning, then calculate the expected number of virus cells after t time. If the answer is too large, then mod result by 10^9+7.So, if the input is like x = 2, y = 4, t = 1, then the output will be 3, because initially, the virus has only one ... Read More

Program to find number of solutions for given equations with four parameters in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:27:41

254 Views

Suppose we have four numbers a, b, c and d and We have to find number of pairs (x, y) can be found such that that follows the equation: x^2 + y^2 = (x*a) + (y*b) where x in range [1, c] and y in range [1, d]So, if the input is like a = 2 b = 3 c = 2 d = 4, then the output will be 1 because one pair is (1, 1).To solve this, we will follow these steps −ans := 0for x in range 1 to c, dol := x*(x-a)det2 := b*b - 4*lif det2 is same as 0 and b is even and 1

Program to find last digit of the given sequence for given n in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:24:02

225 Views

Suppose we have a value n. We have to find the last digit of sequence S. The equation of S is given below −$$\sum_{i=0\: 2^{^{i}}\leqslant n}^{\alpha } \sum_{j=0}^{n} 2^{2^{^{i}+2j}}$$So, if the input is like n = 2, then the output will be 6 because: here only i = 0 and i are valid, soS0 = 2^(2^0 + 0) + 2^(2^0 + 2) + 2^(2^0 + 4) = 42S1 = 2^(2^1 + 0) + 2^(2^1 + 2) + 2^(2^1 + 4) = 84 The sum is 42+84 = 126, so last digit is 6.To solve this, we will follow these steps −total:= 0temp := 1while temp

Program to find position of first event number of line l of a triangle of numbers in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:21:22

187 Views

Suppose we are generating a number triangle like below      1     1 1 1   1 2 3 2 1 1 3 6 7 6 3 1where in each row the elements are generated by adding three numbers on top of it. Now if we have a line number l. We have to find the position of first even number of that line. The position values are starting from 1.So, if the input is like l = 5, then the output will be 2          1       1  1 ... Read More

Program to find sum of the 2 power sum of all subarray sums of a given array in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:05:24

307 Views

Suppose we have a list A. We have taken all non-empty sublists of A as we know a list l with n elements has (2n - 1) non-empty sublist. Now for each sublist, he calculates sublist_sum (the sum of elements and denotes them by S1, S2, S3, ... , S(2N-1)). There is a special sum P such that P = 2S1 + 2S2 +2S3 .... + 2S(2N-1). We have to find P. If P is too large then return P mod (10^9 + 7).So, if the input is like A = [2, 2, 3], then the output will be The ... Read More

Program to check we can reach at position n by jumping or not in Python

Arnab Chakraborty
Updated on 25-Oct-2021 07:02:25

179 Views

Suppose there is a number line from 1 to n. At first we are at position 0, jump one step to go 1, then jump two place to reach at position 3, then jump three position to reach at 6 and so on. We have to check whether maintaining this, we can reach at position n or not.So, if the input is like n = 21, then the output will be True, because 1+2+3+4+5+6 = 21To solve this, we will follow these steps −j:= (1 + square root of (1+8*n)) / 2if |j - int part of j|

Program to find sum of the costs of all simple undirected graphs with n nodes in Python

Arnab Chakraborty
Updated on 25-Oct-2021 06:59:57

339 Views

Suppose we have an undirected graph G with n nodes. Now consider the cost of a simple undirected graph is the sum of the costs of its nodes. And The cost of a node is D^k, where D is its degree. Now we have n and k values. We have to find the sum of the costs of all possible simple undirected graphs with n nodes. The result may be very large, so return the result modulo 1005060097.So, if the input is like n = 3 k = 2, then the output will be 36 because, there are eight simple ... Read More

Advertisements